Skip to content
Advertisement

Delete values over the diagonal in a matrix with python

I have the next problem with a matrix in python and numpy

given this matrix

JavaScript

i want to obtain this:

JavaScript

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement