[SciPy-user] Sparse csr_matrix and column sum

Dinesh B Vadhia dineshbvadhia@hotmail....
Sun Apr 27 18:41:13 CDT 2008


If A is a sparse csr_matrix and you want to calculate the sum of each column then the 'normal' method is:

import numpy
import scipy
from scipy import sparse

colSum = scipy.asmatrix(scipy.zeros((1,J), dtype=numpy.float))
colSum = A.mean(0)

This isn't working.  Do we have to do something else (eg. a todense()) for a sparse matrix?  If so, how?

Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080427/cceec3a7/attachment.html 


More information about the SciPy-user mailing list