[SciPy-user] sparse version of stats.pearsonr ?

Pauli Virtanen pav at iki.fi
Mon Mar 9 21:09:10 EDT 2009


Mon, 09 Mar 2009 19:39:36 -0500, josef.pktd wrote:
[clip]
> I'm not familiar enough with the sparse package to know how the details
> work, but in my first try, `mean` seems strange to me
> 
>>>> B
> <4x4 sparse matrix of type '<type 'numpy.int32'>'
> 	with 4 stored elements in Compressed Sparse Row format>
>>>> B.todense()
> matrix([[3, 0, 1, 0],
>         [0, 2, 0, 0],
>         [0, 0, 0, 0],
>         [0, 0, 0, 1]])
>>>> B.todense().mean(axis=0)
> matrix([[ 0.75,  0.5 ,  0.25,  0.25]])
>>>> B.mean(axis=0)
> matrix([[0, 0, 0, 0]])

Sparse probably uses an integer accumulator for these functions, whereas 
normal numpy arrays use a float accumulator.

Probably a bug: http://projects.scipy.org/scipy/ticket/884

-- 
Pauli Virtanen




More information about the SciPy-User mailing list