ij1994
ij1994

Reputation: 41

Searching only a portion of a matrix in python

I have a symmetric matrix and I am curious if it is possible to only search the upper triangle portion of the matrix using np.where. That is, is there a way to either delete the lower triangular portion of the matrix using a loop or a function so I can search the upper triangular portion of the matrix with np.where?

Upvotes: 0

Views: 153

Answers (1)

glegoux
glegoux

Reputation: 3603

import numpy as np

a = np.array([[1 ,0.42, 0.78], [0.42, 1, 0.73], [0.78, 0.73, 1]])
# k=1 excludes diagonal correlation is 1 
np.where(np.triu(a > 0.7, k=1))

Upvotes: 1

Related Questions