mindspore.numpy.triu_indices_from

mindspore.numpy.triu_indices_from(arr, k=0)[源代码]

Returns the indices for the upper-triangle of arr.

Parameters
  • arr (Union[Tensor, list, tuple]) – 2-dimensional array.

  • k (int, optional) – Diagonal offset, default is 0.

Returns

triu_indices_from, tuple of 2 tensor, shape(N) Indices for the upper-triangle of arr.

Raises
  • TypeError – If arr cannot be converted to tensor, or k is not a number.

  • ValueError – If arr cannot be converted to a 2-dimensional tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> tensor = np.ones((3,3))
>>> print(np.triu_indices_from(tensor))
(Tensor(shape=[6], dtype=Int32, value= [0, 0, 0, 1, 1, 2]),
Tensor(shape=[6], dtype=Int32, value= [0, 1, 2, 1, 2, 2]))