mindspore.numpy.identity
- mindspore.numpy.identity(n, dtype=mstype.float32)[源代码]
Returns the identity tensor.
- 参数
n (int) – Number of rows and columns in the output, must be larger than 0.
dtype (Union[
mindspore.dtype
, str], optional) – Designated tensor dtype, default is mstype.float32.
- 返回
A tensor of shape (n, n), where all elements are equal to zero, except for the diagonal, whose values are equal to one.
- Supported Platforms:
Ascend
GPU
CPU
- 异常
TypeError – If input arguments have types not specified above.
样例
>>> import mindspore.numpy as np >>> print(np.identity(2)) [[1. 0.] [0. 1.]]