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

Robert Kern rkern at ucsd.edu
Thu Dec 2 14:24:12 EST 2004


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.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the SciPy-Dev mailing list