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!

3
  • 3
    Did you look at the numpy documentation? Commented Aug 20, 2016 at 18:22
  • 1
    I believe you will find what you are looking for in the keyword argument axis Commented Aug 20, 2016 at 18:25
  • look up "broadcasting" ( docs.scipy.org/doc/numpy/user/basics.broadcasting.html ) it gets complex pretty quick, so just stick to the basic examples for now. Commented Aug 20, 2016 at 19:06

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

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: stackoverflow.com/questions/8423051/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.