maxframe.tensor.argmax#
- maxframe.tensor.argmax(a, axis=None, out=None)[源代码]#
返回沿轴的最大值的索引。
- 参数:
a (array_like) -- 输入张量。
axis (int, optional) -- 默认情况下,索引是展平张量中的索引,否则沿指定轴。
out (Tensor, optional) -- 如果提供,则结果将插入到此张量中。它应具有适当的形状和数据类型。
- 返回:
index_array -- 张量中索引的张量。它与 a.shape 具有相同的形状,但沿 axis 的维度被移除。
- 返回类型:
Tensor of ints
备注
在最大值多次出现的情况下,返回对应于第一次出现的索引。
示例
>>> import maxframe.tensor as mt
>>> a = mt.arange(6).reshape(2,3) >>> a.execute() array([[0, 1, 2], [3, 4, 5]]) >>> mt.argmax(a).execute() 5 >>> mt.argmax(a, axis=0).execute() array([1, 1, 1]) >>> mt.argmax(a, axis=1).execute() array([2, 2])
N维张量的最大元素的索引:
>>> ind = mt.unravel_index(mt.argmax(a, axis=None), a.shape) >>> ind.execute() (1, 2) >>> a[ind].execute()
>>> b = mt.arange(6) >>> b[1] = 5 >>> b.execute() array([0, 5, 2, 3, 4, 5]) >>> mt.argmax(b).execute() # Only the first occurrence is returned. 1