0

Have a numpy array which was created from pandas values.

It looks like this:

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]])

How can I subtract the np.mean() of it from every single entry of this array?

Thanks in advance!

Merlin
  • 24,552
  • 41
  • 131
  • 206
Keithx
  • 2,994
  • 15
  • 42
  • 71
  • 3
    Did you look at the numpy documentation? – wwii Aug 20 '16 at 18:22
  • 1
    I believe you will find what you are looking for in the keyword argument `axis` – M.T Aug 20 '16 at 18:25
  • look up "broadcasting" ( http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html ) it gets complex pretty quick, so just stick to the basic examples for now. – user1269942 Aug 20 '16 at 19:06

1 Answers1

1

With -:

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()
Daniel
  • 42,087
  • 4
  • 55
  • 81
  • as a side note, this subtracts the OVERALL mean from ALL values. If you wish to subtract the mean of each column from each column, see: http://stackoverflow.com/questions/8423051/remove-mean-from-numpy-matrix – user1269942 Aug 20 '16 at 19:09