If you have an N x N
matrix from which you want the upper triangular values, just do
import numpy as np
N = 5
x = np.arange(N**2).reshape(N, N)
upper = x[np.triu_indices(N, 0)]
If you want the triangular values offset from the main diagonal by k
columns, then do
upper = x[np.triu_indices(N, k)]