mindspore.numpy.diagflat
- mindspore.numpy.diagflat(v, k=0)[源代码]
Creates a two-dimensional array with the flattened input as a diagonal.
Note
On GPU, the supported dtypes are np.float16, and np.float32.
- Parameters
- Returns
Tensor, The 2-D output array.
- Raises
TypeError – If the input is not a tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> 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]]