[SciPy-user] [Sparse matrix library] csr_matrix and column sum

Dinesh B Vadhia dineshbvadhia@hotmail....
Sun Apr 27 23:57:44 CDT 2008


I'm using the svn.  There is no Traceback error but the results are incorrect based on previous results.  Here is ouput from print statements that might help:

> import numpy
> import scipy
> from scipy import sparse

> colSum = scipy.asmatrix(scipy.zeros((1,J), dtype=numpy.float))
> colSum = A.sum(0)            # A is a csr_matrix
> for j in xrange(0, 25, 1):
>     print >> sys.stderr, colSum[0,j],

0 , -44 , 84 , -116 , -121 , -43 , -44 , -116 , -115 , -79 , 70 , -86 , 39 , -17 , -21 , -112 , 29 , -126 , -19 , 33 , 59 , -6 , 24 , 18 , 57

> # This is wrong because the matrix A contains positive integer 1's only.

> colSum = A.todense().sum(0)

> for j in xrange(0, 25, 1):
>    print >> sys.stderr, colSum[0,j],

768 , 724 , 1108 , 652 , 1927 , 2005 , 724 , 908 , 1421 , 1457 , 2118 , 1450 , 1575 , 3055 , 2283 , 656 , 1053 , 898 , 1517 , 1569 , 1339 , 762 , 3096 , 530 , 1081

># This is correct and leads to the correct results but there is a large performance hit because of the .todense()

Hope this helps to identify the problem.

Dinesh


--------------------------------------------------------------------------------

From: Nathan Bell <wnbell <at> gmail.com>
Subject: Re: Sparse csr_matrix and column sum
Newsgroups: gmane.comp.python.scientific.user
Date: 2008-04-28 02:48:41 GMT (1 hour and 43 minutes ago)

On Sun, Apr 27, 2008 at 9:32 PM, Dinesh B Vadhia
<dineshbvadhia <at> hotmail.com> wrote:
>
> Sorry, I wasn't being imprecise as A.sum(0) didn't work and still doesn't -
> I've just tried again.  However, A.todense().sum(0) does work - but takes a
> performance hit.  My import statements are:

You still haven't informed us what exactly "didn't work".  Can you
provide the error message you get when using A.sum(0) where A is a
csr_matrix?  Are you using SciPy from SVN or a previous version?

-- 
Nathan Bell wnbell <at> gmail.com
http://graphics.cs.uiuc.edu/~wnbell/

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


More information about the SciPy-user mailing list