4

I have the following numpy ndarray, the shape is (4,1,2):

    myarray = np.array([[[0.,4.]],
                   [[1.,5.]],
                   [[2.,6.]],
                   [[3.,7.]]])

How do I find the max, min of each column? In this case min, max for 1st column is 0, 3; and min, max for 2nd column is 4, 7.

I can't quite figure out the correct syntax for np.amin and np.amax in this these cases.

Thanks.

1
  • 2
    Try using axis param with those. Read the docs again. Commented Oct 23, 2016 at 7:53

1 Answer 1

5
import numpy as np

myarray = np.array([[[0., 4.]],
                    [[1., 5.]],
                    [[2., 6.]],
                    [[3., 7.]]])
maxes = np.max(myarray,axis=0)
mins = np.min(myarray,axis=0)
print 'maxes are :' ,maxes ,'\nmins are : ', mins

which gives:

maxes are : [[ 3.  7.]] 
mins are :  [[ 0.  4.]]
Sign up to request clarification or add additional context in comments.

Comments

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.