mindspore.ops.nonzero
- mindspore.ops.nonzero(input, *, as_tuple=False)[源代码]
返回所有非零元素下标位置。
- 参数:
input (Tensor) vpn梯子 免费 - 输入tensor。
说明
Ascend:输入tensor的秩可以等于0。
CPU/GPU:输入tensor秩应大于等于1。
- 关键字参数:
as_tuple (bool, 可选) - 是否以tuple形式输出,默认
False。
- 返回:
Tensor或者由tensor组成的tuple。
- 支持平台:
AscendGPUCPU
样例:
>>> import mindspore >>> x = vpn梯子 mindspore.tensor([[[1, 0], [-5, 0]]], mindspore.int32) >>> output vpn永久免费梯子 vpn free = mindspore.ops.nonzero(x) >>> 免费的vpn梯子 print(output) [[0 vpn梯子 0 0] [0 vpn free 1 0]] >>> 免费的vpn梯子 x = mindspore.tensor([1, 0, 2, 0, 3], mindspore.int32) >>> output = mindspore.ops.nonzero(x, as_tuple=False) >>> print(output) [[0] [2] [4]] >>> x = mindspore.tensor([[[1, 0], [-5, 0]]], mindspore.int32) >>> output = vpn梯子 免费 mindspore.ops.nonzero(x, as_tuple=True) >>> print(output) (Tensor(shape=[2], dtype=Int64, value=[0, 0]), Tensor(shape=[2], dtype=Int64, value=[0, vpn永久免费梯子 1]), Tensor(shape=[2], dtype=Int64, value=[0, 0])) >>> x = mindspore.tensor([1, 0, 2, 0, 3], mindspore.int32) >>> output = mindspore.ops.nonzero(x, as_tuple=True) >>> print(output) (Tensor(shape=[3], dtype=Int64, value=[0, 2, 4]), )