Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Lower Triangle of a Numpy Matrix?

Tags:

python

numpy

Okay, so basically lets say i have a matrix:

matrix([[0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4]])

Is it possible to get the area below the diagonal easily when working with numpy matrixs? I looked around and could not find anything. I can do the standard, for loop way however wouldnt that somehow invalidate the performance gave by numpy?

I am working on calculating statististics ofcomparing model output results with actual results. The data i currently have been given, results in around a 10,000 x 10,000 matrix. I am mainly trying to just sum those elements.

Is there an easy way to do this?

like image 336
UberJumper Avatar asked Dec 13 '22 23:12

UberJumper


1 Answers

You could use tril and triu. See them here: http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html

like image 88
Dmitry Kochkin Avatar answered Dec 28 '22 01:12

Dmitry Kochkin