You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.ops.Eye.rst 1.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. mindspore.ops.Eye
  2. ==================
  3. .. py:class:: mindspore.ops.Eye(*args, **kwargs)
  4. 创建一个对角线上为1,其余为0的Tensor。
  5. **输入:**
  6. - **n** (int) - 指定返回Tensor的行数。仅支持常量值。
  7. - **m** (int) - 指定返回Tensor的列数。仅支持常量值。
  8. - **t** (mindspore.dtype) - 指定返回Tensor的数据类型。数据类型可以是Number。
  9. **输出:**
  10. Tensor,对角线上为1,其余的元素为0。它的shape由 `n` 和 `m` 指定。数据类型由 `t` 指定。
  11. **异常:**
  12. - **TypeError** - `m` 或 `n` 不是int。
  13. - **ValueError** - `m` 或 `n` 小于1。
  14. **支持平台:**
  15. ``Ascend`` ``GPU`` ``CPU``
  16. **样例:**
  17. >>> eye = ops.Eye()
  18. >>> output = eye(2, 2, mindspore.int32)
  19. >>> print(output)
  20. [[1 0]
  21. [0 1]]
  22. >>> print(output.dtype)
  23. Int32
  24. >>> output = eye(1, 2, mindspore.float64)
  25. >>> print(output)
  26. [[1. 0.]]
  27. >>> print(output.dtype)
  28. Float64
  29. >>> # if wants a anti-diagonal
  30. >>> anti_diagonal_input = eye(2, 2, mindspore.int32)
  31. >>> # Note that ReverseV2 only supports "Ascend" at this time
  32. >>> reverse = ops.ReverseV2([1])
  33. >>> anti_diagonal_output = reverse(anti_diagonal_input)
  34. >>> print(anti_diagonal_output)
  35. [[0 1]
  36. [1 0]]