mindspore.numpy.triu_indices_from

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

Returns the indices for the upper-triangle of arr.

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

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

返回

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

异常
  • 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

样例

>>> 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]))