numpy: what is the logic of the argmin() and argmax() functions?

后端 未结 5 494
遇见更好的自我
遇见更好的自我 2020-12-23 21:01

I can not understand the output of argmax and argmin when use with the axis parameter. For example:

>>> a = np.array([[1,2         


        
5条回答
  •  甜味超标
    2020-12-23 21:44

    """ ....READ THE COMMENTS FOR CLARIFICATION....."""
    
    import numpy as np
    a = np.array([[1,2,4,7], [9,88,6,45], [9,76,3,4]])
    
    """np.argmax(a) will give index of max value in flatted array of given matrix """
    >>np.arg(max)
    5
    
    """np.argmax(a,axis=0) will return list of indexes of  max value column-wise"""
    >>print(np.argmax(a,axis=0))
    [1,1,1,1]
    
    """np.argmax(a,axis=1) will return list of indexes of  max value row-wise"""
    >>print(np.argmax(a,axis=1))
    [3,1,1]
    
    """np.argmin(a) will give index of min value in flatted array of given matrix """
    >>np.arg(min)
    0
    
    """np.argmin(a,axis=0) will return list of indexes of  min value column-wise"""
    >>print(np.argmin(a,axis=0))
    [0,0,2,2]
    
    """np.argmin(a,axis=0) will return list of indexes of  min value row-wise"""
    >>print(np.argmin(a,axis=1))
    [0,2,2]
    

提交回复
热议问题