Remove mean from numpy matrix

后端 未结 4 1273
渐次进展
渐次进展 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:01

    You can also use matrix instead of array. Then you won't need to reshape:

    >>> A = np.matrix([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])
    >>> m = A.mean(axis=1)
    >>> A - m
    matrix([[-1.,  0.,  1.],
            [-1.,  0.,  1.],
            [-1.,  0.,  1.],
            [-1.,  0.,  1.]])
    

提交回复
热议问题