[Scipy-tickets] [SciPy] #1859: Sparse matrix subtraction with another matrix seems to regard the other matrix as a scalar

SciPy Trac scipy-tickets@scipy....
Fri Mar 1 21:00:37 CST 2013


#1859: Sparse matrix subtraction with another matrix seems to regard the other
matrix as a scalar
------------------------------------+---------------------------------------
 Reporter:  photon.engine           |       Owner:  jakevdp    
     Type:  defect                  |      Status:  new        
 Priority:  normal                  |   Milestone:  Unscheduled
Component:  scipy.sparse            |     Version:  0.10.1     
 Keywords:  sparse scalar subtract  |  
------------------------------------+---------------------------------------

Comment(by photon.engine):

 I'll try .dot() on my code, thanks for the suggestion.

 I must admit I'm new to this SciPy business (worked with NumPy for some
 time), so I'm not sure how CSR and DIA matrices differ. I tried to
 reproduce your results with

 {{{
 import numpy
 import scipy.sparse

 c = scipy.sparse.csr_matrix([[1,0,0],[2,3,0],[0,0,4]])
 d = scipy.sparse.dia_matrix([[1,0,0],[2,3,0],[0,0,4]])
 x = numpy.array([10, 20, 30])

 print(c.toarray())
 print(d.toarray())

 print(numpy.dot(c, x).shape, numpy.dot(c, x).dtype)
 print(c.dot(x))
 print(numpy.dot(d, x).shape, numpy.dot(d, x).dtype)
 print(d.dot(x))
 }}}

 and I got

 {{{
 [[1 0 0]
  [2 3 0]
  [0 0 4]]
 [[1 0 0]
  [2 3 0]
  [0 0 4]]
 (3,) object
 [ 10  80 120]
 (3,) object
 [ 10  80 120]
 }}}

 So the only difference is that, on my computer, CSR doesn't crash.
 However, it still doesn't quite explain why I received the particular
 error message about scalars...

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1859#comment:2>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list