maxframe.tensor.argwhere#

maxframe.tensor.argwhere(a)[源代码]#

查找张量中非零元素的索引,并按元素分组。

参数:

a (array_like) -- 输入数据。

返回:

index_tensor -- 非零元素的索引。索引按元素分组。

返回类型:

Tensor

参见

where, nonzero

备注

mt.argwhere(a) 等价于 mt.transpose(mt.nonzero(a))

argwhere 的输出不适合用于索引张量。为此,请使用 nonzero(a)

示例

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