[SciPy-user] Sparse csr_matrix and column sum

Dinesh B Vadhia dineshbvadhia at hotmail.com
Sun Apr 27 19:41:13 EDT 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://mail.scipy.org/pipermail/scipy-user/attachments/20080427/cceec3a7/attachment.html>


More information about the SciPy-User mailing list