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

SciPy Trac scipy-tickets@scipy....
Thu Apr 18 17:45:22 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):

 Hello Izzy, by
 [http://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html
 definition] the behavior of {{{numpy.multiply}}} should be pointwise
 multiplication. So that should be the expected behavior for this.

 However it looks like {{{numpy.multipy}}} calls {{{spmatrix.__mul__}}}
 which does matrix multiplication by default. I don't know how to fix this
 without changing {{{__mul__}}} to pointwise mult which would break things.

 I'm submitting a patch for the {{{sparse.multiply}}} 'inconsistent shapes'
 bug that you noted. so it  should work now. If we could somehow redirect
 {{{numpy.multiply}}} on {{{spmatrix}}} objects to use {{{ sparse.multiply
 }}} I think that would correct the issue initially reported.

 {{{nump.matrix}}} has the correct behavior, so we could probably just copy
 what it does:
 {{{
 In [10]: Am, Bm
 Out[10]:
 (matrix([[4, 1, 1],
         [4, 2, 4],
         [4, 3, 3]]),
  matrix([[4, 4, 1],
         [0, 3, 1],
         [1, 2, 0]]))

 In [11]: np.multiply(Am, Bm)
 Out[11]:
 matrix([[16,  4,  1],
         [ 0,  6,  4],
         [ 4,  6,  0]])

 In [12]: Am*Bm
 Out[12]:
 matrix([[17, 21,  5],
         [20, 30,  6],
         [19, 31,  7]])
 }}}

 Otherwise, it looks like there is plenty of work for us!

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


More information about the Scipy-tickets mailing list