[Scipy-tickets] [SciPy] #1042: sparse matrix failed with element-wise multiplication using numpy.multiply()

SciPy Trac scipy-tickets@scipy....
Thu Apr 18 00:16:51 CDT 2013


#1042: sparse matrix failed with element-wise multiplication using
numpy.multiply()
--------------------------+-------------------------------------------------
 Reporter:  dingle        |       Owner:  wnbell
     Type:  defect        |      Status:  new   
 Priority:  normal        |   Milestone:        
Component:  scipy.sparse  |     Version:  0.7.0 
 Keywords:  multiply      |  
--------------------------+-------------------------------------------------

Comment(by cowlicks):

 It looks like when np.multiply is passed an ndarray objects it first tries
 to do matrix multiplication on them, if this fails due to a 'dimension
 mismatch', it does pointwise multiplication (element by element).

 However when np.multiply is passed a spmatrix object it asks
 {{{spmatrix.__mul__}}} what to do. Where it tries to do matrix
 multiplication, but if this has a dimension mismatch fails it just coughs
 up the value error seen. I'll try to patch this tomorrow by falling back
 on pointwise multiplication when there is a dimension mismatch, like the
 ndarrays do.

 {{{
 In [8]: np.multiply(A, B)
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)
 <ipython-input-8-ab35b70fd7b3> in <module>()
 ----> 1 np.multiply(A, B)

 /usr/lib/python2.7/dist-packages/scipy/sparse/base.pyc in __mul__(self,
 other)
     244         if issparse(other):
     245             if self.shape[1] != other.shape[0]:
 --> 246                 raise ValueError('dimension mismatch')
     247             return self._mul_sparse_matrix(other)
     248

 ValueError: dimension mismatch
 }}}

 Also, I realize this is an old ticket, but you say {{{ a.multiply(b) }}}
 works. However standard nd.arrays don't have a multiply method... So maybe
 I'm missing something?

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


More information about the Scipy-tickets mailing list