np.triu_indices_from()
返回方阵的上三角矩阵的索引
numpy.triu_indices_from(arr,k = 0 )
参数:
arr :ndarray,shape(N,N)
k: int,可选,对角线偏移
例子:
import numpy as np a = np.array([[1,2],[4,5]]) np.triu_indices_from(a) #(array([0, 0, 1], dtype=int64), array([0, 1, 1], dtype=int64))
https://numpy.org/doc/stable/reference/generated/numpy.triu_indices_from.html