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

Nils Wagner nwagner at mecha.uni-stuttgart.de
Thu Dec 2 03:04:20 CST 2004


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)

rows, cols, entries, rep, field, symm = io.mminfo('k0.mtx')
print 'number of rows, cols and entries', rows, cols, entries
print 'Start reading matrix - this may take a minute'
ma = io.mmread('k0.mtx')
print 'Finished'
flag = 1
if flag == 1:
 spy2(ma)
 show()

It failed. Is it somehow possible to visualize sparse matrices ?
Any suggestion would be appreciated.

Thanks in advance

                                     Nils

number of rows, cols and entries 67986 67986 4222171
Start reading matrix - this may take a minute
Finished
Traceback (most recent call last):
  File "spy.py", line 29, in ?
    spy2(ma)
  File "spy.py", line 19, in spy2
    Z = where(Z>0,1.,0.)
  File "/usr/lib/python2.3/site-packages/scipy/sparse/Sparse.py", line 145, in __cmp__
    raise TypeError, "Comparison of sparse matrices is not implemented."
TypeError: Comparison of sparse matrices is not implemented.






More information about the Scipy-dev mailing list