mindspore.numpy.diagflat
- mindspore.numpy.diagflat(v, k=0)[源代码]
Creates a two-dimensional array with the flattened input as a diagonal.
说明
On GPU, the supported dtypes are np.float16, and np.float32.
- 参数
- 返回
Tensor, The 2-D output array.
- 异常
TypeError – If the input is not a tensor.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> output = np.diagflat(np.asarray([[1,2], [3,4]])) >>> print(output) [[1 0 0 0] [0 2 0 0] [0 0 3 0] [0 0 0 4]] >>> output = np.diagflat(np.asarray([1,2]), 1) >>> print(output) [[0 1 0] [0 0 2] [0 0 0]]