mindspore.numpy.diag_indices
- mindspore.numpy.diag_indices(n, ndim=2)[源代码]
Returns the indices to access the main diagonal of an array.
This returns a tuple of indices that can be used to access the main diagonal of an array a with
a.ndim >= 2
dimensions and shape (n, n, …, n). Fora.ndim = 2
this is the usual diagonal, fora.ndim > 2
this is the set of indices to accessa[i, i, ..., i]
fori = [0..n-1]
.- Parameters
- Returns
Tuple of Tensor.
- Raises
TypeError – If input are not integers.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> output = np.diag_indices(5, 3) >>> print(output) (Tensor(shape=[5], dtype=Int32, value= [0, 1, 2, 3, 4]), Tensor(shape=[5], dtype=Int32, value= [0, 1, 2, 3, 4]), Tensor(shape=[5], dtype=Int32, value= [0, 1, 2, 3, 4]))