I have the next problem with a matrix in python and numpy
given this matrix
JavaScript
x
6
1
Cmpd1 Cmpd2 Cmpd3 Cmpd4
2
Cmpd1 1 0.32 0.77 0.45
3
Cmpd2 0.32 1 0.14 0.73
4
Cmpd3 0.77 0.14 1 0.29
5
Cmpd4 0.45 0.73 0.29 1
6
i want to obtain this:
JavaScript
1
6
1
Cmpd1 Cmpd2 Cmpd3 Cmpd4
2
Cmpd1 1
3
Cmpd2 0.32 1
4
Cmpd3 0.77 0.14 1
5
Cmpd4 0.45 0.73 0.29 1
6
I was trying with np.diag() but doesnt works
Thanks!
Advertisement
Answer
Use np.tril(a)
to extract the lower triangular matrix.
Refer this : https://docs.scipy.org/doc/numpy/reference/generated/numpy.tril.html