-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sparse matrix failed with element-wise multiplication using numpy.multiply() (Trac #1042) #1569
Comments
trac user cowlicks wrote on 2013-04-18 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
Also, I realize this is an old ticket, but you say |
trac user izzycecil wrote on 2013-04-18 I think they must have meant asp.multiply(bsp). I was tinkering around with this bug last night, and found a number of odd behaviors.
We have this known fail case
But then, I looked at multiplying a sparse matrix by an array...
Where if a normal matrix was multiplied by an array,
I would think we would want sparse matrices to simply work like a normal matrix. Or was this indeed the desired behavior? np.multiply(asp,d) will actually return the same result, with type matrix instead of array. Then I looked at spmatrix.multiply...
It's not playing nice with Array's. This is because of the way it looks at the shape of "other" --- an easy fix. Looking through the code, I have a pretty good understanding of why all of these are happening, but I'm confused on what the desired behaviors should be. We want spmatrix to essentially act as a matrix, yes? It also seems like there should be more separation between point-wise and matrix multiplication. Am I being nieve? |
trac user cowlicks wrote on 2013-04-18 Hello Izzy, by [http://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html definition] the behavior of However it looks like I'm submitting a patch for the
Otherwise, it looks like there is plenty of work for us! |
@pv wrote on 2013-04-19 The problem with
Note that it's an 0-dim object array containing the lil_matrix. One fix is to add an That's a quick and dirty way to fix up the interoperability a bit. A better way would be to fix Numpy so that it does something sensible, such as optionally falling back to |
Fixed in gh-2869 |
Original ticket http://projects.scipy.org/scipy/ticket/1042 on 2009-11-04 by trac user dingle, assigned to @wnbell.
If a and b are sparse matrices as follows:
But a.multiply(b) works fine. I think they should be identical.
The text was updated successfully, but these errors were encountered: