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

后端 未结 5 506
遇见更好的自我
遇见更好的自我 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:41

    The axis in the argmax function argument, refers to the axis along which the array will be sliced.

    In another word, np.argmin(a,axis=0) is effectively the same as np.apply_along_axis(np.argmin, 0, a), that is to find out the minimum location for these sliced vectors along the axis=0.

    Therefore in your example, np.argmin(a, axis=0) is [0, 0, 2, 2] which corresponding to values of [1, 2, 3, 4] on respective columns

提交回复
热议问题