Matrix Structure Plots

Does it work for SciPy sparse matrices

    > (e.g. scipy.sparse.csr_matrix)? I don't think so... That
    > is why I provided my solution. Otherwise, of course, I am
    > well aware of spy, spy2 :slight_smile:

I see -- can you post a simple example (with version nums for
numpy/scipy/mpl) that exposes the bug. Hopefully there will be an
easy fix.

JDH

John Hunter wrote:

"Robert" == Robert Cimrman <cimrman3@...1098...> writes:

    > Does it work for SciPy sparse matrices
    > (e.g. scipy.sparse.csr_matrix)? I don't think so... That
    > is why I provided my solution. Otherwise, of course, I am
    > well aware of spy, spy2 :slight_smile:

I see -- can you post a simple example (with version nums for
numpy/scipy/mpl) that exposes the bug. Hopefully there will be an
easy fix.

Sure:

matplotlib: 0.87.2-r2

from SVN:
numpy: Checked out revision 2433.
scipy: Checked out revision 1888.

The problem is, that you cannot use 'where' for sparse matrices yet...

In [14]:import scipy.sparse as sp
In [15]:import scipy as nm
In [16]:a = nm.array( [[1, 0, 2, 0, 3]] )
In [17]:b = sp.csr_matrix( a )
In [18]:b
Out[18]:
<1x5 sparse matrix of type '<type 'float64scalar'>'
         with 3 stored elements (space for 3)
         in Compressed Sparse Row format>

In [19]:stuck_out_tongue: b
   (0, 0) 1.0
   (0, 2) 2.0
   (0, 4) 3.0

In [20]:spy(b )

···

---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)

/home/eldaran/<console>

/usr/lib/python2.4/site-packages/matplotlib/pylab.py in spy(*args, **kwargs)
    2184 hold(h)
    2185 try:
-> 2186 ret = gca().spy(*args, **kwargs)
    2187 draw_if_interactive()
    2188 except:

/usr/lib/python2.4/site-packages/matplotlib/axes.py in spy(self, Z, marker, markersize, **kwargs)
    3557 The line handles are returned
    3558 """
-> 3559 x,y,z = matplotlib.mlab.get_xyz_where(Z, Z>0)
    3560 return self.plot(x+0.5,y+0.5, linestyle='None',
    3561 marker=marker,markersize=markersize, **kwargs)

/usr/lib/python2.4/site-packages/scipy/sparse/sparse.py in __cmp__(self, other)

TypeError: comparison of sparse matrices not implemented

In [23]:spy( a )
Out[23]:[<matplotlib.lines.Line2D instance at 0xb5709aac>]