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
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.