[SciPy-user] SciPy_Tutorial sparse examples broken

Kael Fischer kael.fischer@gmail....
Thu Mar 12 17:12:52 CDT 2009


The "new" Tutorial (most of it is from 2006) sparse matrix examples
seem to have a problem.  I'm using SciPy 0.7.0.b1 on FreeBSD 7.0R
amd64.

setup like this, per tutorial:
###
Asp = sparse.lil_matrix((50000,50000))
Asp.setdiag(ones(50000))
b = arange(0,50000)
###

Now Asp.tocsc(), Asp.tocsr(),linsolve.spsolve.(Asp,b) all work, but it
you assign to Asp with some fancy indexing along dimension 0 tocsc and
tocsr (and hence many other methods) fail.  E.g.:
###
Asp[200:250,30] = 10*random.rand(50)
### or ###
Asp[0:3,30] = [1,2,3]
###

followed by:
###
Asp.tocsr()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/nfs/r1/home/fishnet/taxBootstrap/<ipython console> in <module>()

/usr/local/lib/python2.5/site-packages/scipy/sparse/lil.pyc in tocsr(self)
    425         for x in self.data:
    426             data.extend(x)
--> 427         data = np.asarray(data, dtype=self.dtype)
    428
    429         from csr import csr_matrix

/usr/local/lib/python2.5/site-packages/numpy/core/numeric.pyc in
asarray(a, dtype, order)
    228
    229     """
--> 230     return array(a, dtype, copy=False, order=order)
    231
    232 def asanyarray(a, dtype=None, order=None):

ValueError: setting an array element with a sequence.
###

Note other types of assignment, like fancy indexing on dimension 1
with the same right sides, do not cause this problem.  I was going to
fix the wiki but this seems like a bug.


-Kael



Kael Fischer, Ph.D
Research Assistant Professor
Department of Pathology, Univ. of Utah
(801) 213-3766


More information about the SciPy-user mailing list