mindspore.ops.Eye

查看源文件
class mindspore.ops.Eye[源代码]

返回一个主对角线上元素为1,其余元素为0的tensor。

输入:
  • n (int) - 返回的行数。

  • m (int) - 返回的列数。

  • t (mindspore.dtype) - 返回的数据类型。

输出:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> eye = mindspore.ops.Eye()
>>> output = eye(3, 3, mindspore.int32)
>>> print(output)
[[1 0 0]
 [0 1 0]
 [0 0 1]]
>>>
>>> output = eye(3, 4, mindspore.float32)
>>> print(output)
[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]]