how to find minimum/maximum values axis by axis in numpy array

后端 未结 1 1260
无人共我
无人共我 2021-01-14 06:11

I have a NumPy array with a shape of (3,1,2):

A=np.array([[[1,4]],
            [[2,5]],
            [[3,2]]]).

I\'d like to ge

1条回答
  •  伪装坚强ぢ
    2021-01-14 06:53

    You can specify axis as parameter to numpy.min function.

    In [10]: A=np.array([[[1,4]],
                    [[2,5]],
                    [[3,6]]])
    
    In [11]: np.min(A)
    Out[11]: 1
    
    In [12]: np.min(A, axis=0)
    Out[12]: array([[1, 4]])
    
    In [13]: np.min(A, axis=1)
    Out[13]: 
    array([[1, 4],
           [2, 5],
           [3, 6]])
    
    In [14]: np.min(A, axis=2)
    Out[14]: 
    array([[1],
           [2],
           [3]])
    

    0 讨论(0)
提交回复
热议问题