[SciPy-user] sparse.lil_matrix accepts array assignments to elements

Nathan Bell wnbell@gmail....
Sat Mar 21 13:26:10 CDT 2009

On Fri, Mar 20, 2009 at 12:33 PM, Andrew Hawryluk <HAWRYLA@novachem.com> wrote:
> Hi, we noticed an unexpected behaviour in sparse.lil_matrix today. The
> following runs without errors:
> import numpy as np
> from scipy import sparse
> a = sparse.lil_matrix((10,10))
> a[0,0] = np.array([3.1415926,3.1415926])
> I would have expected some error ('angry red text' in IDLE) when I tried
> to assign a 1D array to a single element of the sparse array, but no
> error occurs. (This assignment was a bug in our code.) We found the
> error later when we tried a.tocsr().
> Should there be a type-check of some sort in sparse.lil_matrix to
> prevent this?

Thanks for the report.  It should raise a ValueError in r5630:

We'll merge this into 0.7.1 so you don't have to wait for 0.8

Nathan Bell wnbell@gmail.com

More information about the SciPy-user mailing list