Python基本函数:np.argmax()

2022-10-06 10:05:33

Python基本函数:np.argmax()

格式:np.argmax(a)
注意:返回的是a中元素最大值所对应的索引值

一、函数说明

argmax(a, axis=None, out=None)
    Returns the indices of the maximum values along an axis.#返回向量的最大值的索引

    Parameters----------
    a: array_like
        Input array.
    axis:int, optional
        By default, the indexis into the flattened array, otherwise
        along the specified axis.
    out: array, optional
        If provided, the result will be inserted into this array. It should
        be of the appropriate shapeand dtype.

  返回元素最大值所对应的索引值!若还是没看明白,下面则是例子来辅助理解。

二、函数用法

1、一维数组

In:       	a= np.array([3,1,2,1,3,5])
Out:[3,1,2,1,3,5]

In: 		b= np.argmax(a)# 元素最大值的索引值
Out:5

2、二维数组

In:       	a= np.array([[1,3,5,7],[5,7,2,2],[4,6,8,1]])
Out:[[1,3,5,7],[5,7,2,2],[4,6,8,1]]

In: 		b= np.argmax(a, axis=0)# 对数组按列方向搜索最大值
Out:[1120]       

In: 		b= np.argmax(a, axis=1)# 对数组按行方向搜索最大值
Out:[312]
  • 作者:Raywit
  • 原文链接:https://blog.csdn.net/qq_40520596/article/details/102808750
    更新时间:2022-10-06 10:05:33