mindspore.numpy.identity
- mindspore.numpy.identity(n, dtype=mstype.float32)[源代码]
- 返回单位数组。主对角线上全为1。 - 参数:
- n (int) - 设置的输出数组的行数和列数,必须大于0。 
- dtype (Union[mindspore.dtype, str], 可选) - 指定的Tensor - dtype,默认值:- mstype.float32。
 
- 返回:
- Tensor,shape为 - (n, n),除主对角线上值为1,其余所有元素都等于0。
- 异常:
- TypeError - 如果输入参数非上述给定的类型。 
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore.numpy as np >>> print(np.identity(2)) [[1. 0.] [0. 1.]]