【发布时间】:2017-12-02 10:00:58
【问题描述】:
对于二维数组,我正在尝试创建一个标准化函数,它应该按行和按列工作。我不确定当使用axis = 1(按行)给出参数时该怎么做。
def standardize(x, axis=None):
if axis == 0:
return (x - x.mean(axis)) / x.std(axis)
else:
?????
我尝试在这部分将axis 更改为axis = 1:(x - x.mean(axis)) / x.std(axis)
然后我得到以下错误:
ValueError: operands could not be broadcast together with shapes (4,3) (4,)
谁能解释一下我还是个初学者该怎么做?
【问题讨论】:
-
检查此链接stackoverflow.com/questions/12525722/normalize-data-in-pandas,看看您是否可以相应地调整您的代码。用例子很好地说明了这一点。
标签: python matrix standardized