np.argmax(array, axis)
np.argmax()这个函数返回的就是数组array中最大值的索引值.
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 index is 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 shape and 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: [1 1 2 0]
In : b = np.argmax(a, axis=1) # 对数组按行方向搜索最大值
Out: [3 1 2]