# [SciPy-dev] Feature request : Comparison of sparse matrices is not implemented.

Nils Wagner nwagner at mecha.uni-stuttgart.de
Fri Dec 3 04:43:17 CST 2004

```Robert Kern wrote:

> Nils Wagner wrote:
>
>> Robert Kern wrote:
>>
>>> Nils Wagner wrote:
>>>
>>>> Hi all,
>>>>
>>>> I tried to visualize the structure of large and sparse matrices using
>>>>
>>>> from matplotlib.colors import LinearSegmentedColormap
>>>> from matplotlib.matlab import *
>>>> from scipy import *
>>>> import IPython
>>>>
>>>> def spy2(Z):
>>>>    """
>>>>    SPY(Z) plots the sparsity pattern of the matrix S as an image
>>>>    """
>>>>
>>>>    #binary colormap min white, max black
>>>>    cmapdata = {
>>>>         'red'  :  ((0., 1., 1.), (1., 0., 0.)),
>>>>         'green':  ((0., 1., 1.), (1., 0., 0.)),
>>>>         'blue' :  ((0., 1., 1.), (1., 0., 0.))
>>>>         }
>>>>    binary =  LinearSegmentedColormap('binary',  cmapdata, 2)
>>>>
>>>>    Z = where(Z>0,1.,0.)
>>>>    imshow(transpose(Z), interpolation='nearest', cmap=binary)
>>>
>>>
>>>
>>>
>>> Since imshow() doesn't deal with sparse matrices (to my knowledge),
>>> but only dense matrices, you need to use Z.todense() regardless.
>>>
>> This might be a memory problem for such large matrices arising in  my
>> applications...
>> Just, to receive an impression the number of rows, cols and entries
>> are 67986, 67986 and 4222171, respectively.
>
>
> Then you'll have to patch imshow to deal with sparse matrices.
>
Is there someone who can help me with that task ?

Nils

```