The first thing I'm surprised about with scipy.sparse is that it uses the matrix type instead of the array type. This is very unfortunate, in my opinion. The bug is that a sparse matrix won't work correctly with `dot` and `array`: spmat = speye(3,3) vec = array([1,0,0]) dot(spmat, vec) returns: array([ (0, 0) 1.0 (1, 1) 1.0 (2, 2) 1.0, (0, 0) 0.0 (1, 1) 0.0 (2, 2) 0.0, (0, 0) 0.0 (1, 1) 0.0 (2, 2) 0.0], dtype=object) Ouch!! The right result may however be obtained with spmat * vec. This is a pity because any code that works with arrays or matrices in general and uses `dot` to do the matrix vector multiplication will be *broken* with sparse matrices. How reliable is scipy.sparse? Is there any plan to make it more compatible with the array type? Behave like the array type? How can I help? == Olivier
Nobody seems to care much about sparse arrays in scipy.... One reason why i tremendously prefer arrays over matrices is that it is extremely easy to multiply all the rows or columns of a matrix by a vector of coefficients. You just do M*V to multiply column-wise or M*V.reshape(-1,1) to multiply row-wise. I hate having to create a diagonal matrix for such a simple task. Nobody is interested in having sparse arrays in scipy? == Olivier On Oct 31, 12:01 pm, "Olivier Verdier" <zelb...@gmail.com> wrote:
The first thing I'm surprised about with scipy.sparse is that it uses the matrix type instead of the array type. This is very unfortunate, in my opinion. The bug is that a sparse matrix won't work correctly with `dot` and `array`:
spmat = speye(3,3) vec = array([1,0,0])
dot(spmat, vec) returns: array([ (0, 0) 1.0 (1, 1) 1.0 (2, 2) 1.0, (0, 0) 0.0 (1, 1) 0.0 (2, 2) 0.0, (0, 0) 0.0 (1, 1) 0.0 (2, 2) 0.0], dtype=object)
Ouch!!
The right result may however be obtained with spmat * vec.
This is a pity because any code that works with arrays or matrices in general and uses `dot` to do the matrix vector multiplication will be *broken* with sparse matrices.
How reliable is scipy.sparse? Is there any plan to make it more compatible with the array type? Behave like the array type? How can I help?
== Olivier
_______________________________________________ SciPy-user mailing list SciPy-u...@scipy.orghttp://projects.scipy.org/mailman/listinfo/scipy-user
On Thu, Nov 01, 2007 at 06:06:29PM -0000, Olivier wrote:
Nobody seems to care much about sparse arrays in scipy.... One reason why i tremendously prefer arrays over matrices is that it is extremely easy to multiply all the rows or columns of a matrix by a vector of coefficients. You just do M*V to multiply column-wise or M*V.reshape(-1,1) to multiply row-wise.
I hate having to create a diagonal matrix for such a simple task.
Nobody is interested in having sparse arrays in scipy?
It's not that we aren't interested, but someone has to write it. The sparse matrix base classes need to support dot, element-wise multiplication and broadcasting. Then it is a simple matter of subclassing and overriding * to get matrix functionality. Nathan has really done a lot to improve the underlying engine, but the Python end of things could do with a good refactoring. Cheers Stéfan
Hi Olivier On Wed, 31 Oct 2007 12:01:50 +0100, Olivier Verdier wrote:
The first thing I'm surprised about with scipy.sparse is that it uses the matrix type instead of the array type. This is very unfortunate, in my opinion. The bug is that a sparse matrix won't work correctly with `dot` and `array`:
This is a pity because any code that works with arrays or matrices in general and uses `dot` to do the matrix vector multiplication will be *broken* with sparse matrices.
Yeah, I agree this is a bit irritating sometimes. OTOH you usually know when you are dealing with sparse matrices since they tend to be fairly specific in their application.
How reliable is scipy.sparse? Is there any plan to make it more compatible with the array type? Behave like the array type? How can I help?
I find it to be quite reliable for my work (i.e. WorksForMe), but I've been using spmat.matvec() since the beginning. I use SVN versions of scipy/numpy since the sparse bits seem to improve faster than the release cycles come around. Of course you can always help by reporting bugs and making patches for things you think could be better. There's a lot to be done. The trick is not to be shy, if your patches are OK they'll get applied quickly, and the worst that can happen is that someone will say no ;P Regards Neilen
participants (4)
-
Neilen Marais
-
Olivier
-
Olivier Verdier
-
Stefan van der Walt