mindspore.numpy.identity
- mindspore.numpy.identity(n, dtype=mstype.float32)[源代码]
Returns the identity tensor.
- Parameters
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 ismstype.float32
.
- Returns
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
- Raises
TypeError – If input arguments have types not specified above.
Examples
>>> import mindspore.numpy as np >>> print(np.identity(2)) [[1. 0.] [0. 1.]]