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

Nathan Bell wnbell@gmail....
Mon Apr 28 00:29:29 CDT 2008


On Sun, Apr 27, 2008 at 11:57 PM, Dinesh B Vadhia
<dineshbvadhia@hotmail.com> wrote:
>
> 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
>
>
> 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 due to the fact that when integer arithmetic overflows (e.g. A
+ B is too large) the result "wraps around".  The solution is to use a
data type with a greater range of values (more bits).

Replace your int8 data array with an int16 array and you will get the
expected results (albeit using one more byte per nonzero) provided
that the sums do not exceed 2^15 - 1.

To be safe, you might use int32 and not worry about ranges as much.

-- 
Nathan Bell wnbell@gmail.com
http://graphics.cs.uiuc.edu/~wnbell/


More information about the SciPy-user mailing list