maxframe.tensor.argmin#

maxframe.tensor.argmin(a, axis=None, out=None)[源代码]#

返回沿轴的最小值的索引。

参数:
  • a (array_like) -- 输入张量。

  • axis (int, optional) -- 默认情况下,索引是展平张量中的索引,否则沿指定轴。

  • out (Tensor, optional) -- 如果提供,则结果将插入到此张量中。它应该具有适当的形状和数据类型。

返回:

index_array -- 张量中索引的张量。它的形状与 a.shape 相同,但沿 axis 的维度被移除。

返回类型:

Tensor of ints

参见

Tensor.argmin, argmax

amin

沿给定轴的最小值。

unravel_index

将平面索引转换为索引元组。

备注

在最小值多次出现的情况下,返回对应于第一次出现的索引。

示例

>>> import maxframe.tensor as mt
>>> a = mt.arange(6).reshape(2,3)
>>> a.execute()
array([[0, 1, 2],
       [3, 4, 5]])
>>> mt.argmin(a).execute()
0
>>> mt.argmin(a, axis=0).execute()
array([0, 0, 0])
>>> mt.argmin(a, axis=1).execute()
array([0, 0])

N维张量的最小元素的索引:

>>> ind = mt.unravel_index(mt.argmin(a, axis=None), a.shape)
>>> ind.execute()
(0, 0)
>>> a[ind]
>>> b = mt.arange(6)
>>> b[4] = 0
>>> b.execute()
array([0, 1, 2, 3, 0, 5])
>>> mt.argmin(b).execute()  # Only the first occurrence is returned.
0