Remove mean from numpy matrix

后端 未结 4 1261
渐次进展
渐次进展 2021-02-07 02:47

I have a numpy matrix A where the data is organised column-vector-vise i.e A[:,0] is the first data vector, A[:,1] is the second and so on

4条回答
  •  隐瞒了意图╮
    2021-02-07 03:11

    Looks like some of these answers are pretty old, I just tested this on numpy 1.13.3:

    >>> import numpy as np
    >>> a = np.array([[1,1,3],[1,0,4],[1,2,2]])
    >>> a
    array([[1, 1, 3],
           [1, 0, 4],
           [1, 2, 2]])
    >>> a = a - a.mean(axis=0)
    >>> a
    array([[ 0.,  0.,  0.],
           [ 0., -1.,  1.],
           [ 0.,  1., -1.]])
    

    I think this is much cleaner and simpler. Have a try and let me know if this is somehow inferior than the other answers.

提交回复
热议问题