2016-08-20 151 views
0

有一个由pandas值创建的numpy数组。使用numpy数组元素的操作

它看起来像这样:

array([[ 230.1, 37.8, 69.2], 
     [ 44.5, 39.3, 45.1], 
     [ 17.2, 45.9, 69.3], 
     [ 151.5, 41.3, 58.5], 
     [ 180.8, 10.8, 58.4]]) 

如何从这个数组中的每一个条目减去它的np.mean()?

在此先感谢!

+3

你看看numpy的文件? – wwii

+1

我相信你会发现你正在寻找关键字参数'轴' –

+0

查找“广播”(http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)它变得复杂非常快,所以现在就坚持基本的例子。作为旁注, – user1269942

回答

1

随着-

a = array([[ 230.1, 37.8, 69.2], 
    [ 44.5, 39.3, 45.1], 
    [ 17.2, 45.9, 69.3], 
    [ 151.5, 41.3, 58.5], 
    [ 180.8, 10.8, 58.4]]) 
a -= a.mean() 
+0

,这会从ALL值中减去OVERALL平均值。如果您想从每列中减去每列的平均值,请参阅:http://stackoverflow.com/questions/8423051/remove-mean-from-numpy-matrix – user1269942