Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding min max in 3d numpy array

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.

like image 921
Perceptron Avatar asked Oct 18 '25 06:10

Perceptron


1 Answers

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.]]
like image 200
Kennet Celeste Avatar answered Oct 21 '25 21:10

Kennet Celeste