[SciPy-User] sparse array hstack

Skipper Seabold jsseabold at gmail.com
Mon May 17 13:32:23 EDT 2010


On Thu, May 13, 2010 at 10:26 AM, Jason Rennie <jrennie at gmail.com> wrote:
> It appears that numpy.hstack doesn't work with scipy sparse arrays.  I'm
> using scipy 0.6.0 (Debian stable).  Am I observing correctly?  Does a later
> version of numpy/scipy fix this?  Or, is there code available which will do
> an hstack on sparse arrays?
> Thanks,
> Jason

You want to use scipy.sparse.hstack, which works for me with recent scipy trunk

In [20]: from scipy import sparse

In [21]: a = sparse.lil_matrix((10,10))

In [22]: a[0,0]=100

In [23]: b = sparse.lil_matrix((10,10))

In [24]: b[0,0] = 99

In [25]: c = sparse.hstack([a,b])

In [26]: c.toarray()
<snip>

Skipper



More information about the SciPy-User mailing list