[SciPy-user] Creating a sparse matrix

Nathan Bell wnbell at gmail.com
Mon Dec 17 23:52:37 EST 2007


Nils Wagner <nwagner <at> iam.uni-stuttgart.de> writes:

> Many thanks.
> The file contains only the upper triangular part of the
> symmetric matrix. How can I add the lower part to A ?

starting with row,col,data do the following:

mask = row != col #off-diagonal mask
new_row = concatenate((row,col[mask]))
new_col = concatenate((col,row[mask]))
new_data = concatenate((data,data[mask]))

This adds the transpose of the off-diagonal part of the matrix to the matrix.





More information about the SciPy-User mailing list