# [SciPy-User] Sparse matrices and dot product

Sebastian Walter sebastian.walter@gmail....
Sun Nov 28 13:47:35 CST 2010

```I apologize for being a little unrelated to the original topic of this
discussion: I don't use sparse matrices a lot, so this specific `dot`
problem is not an issue for me.
However, I noticed that when I first joined this mailing list there
seemed to be a strong agreement among the subscribers that
`A.dot(B)` is "evil". IIRC the argument was something similar to
"there should be only one obvious way".

Now I'm confused that everyone seems to be in favor of the
Consider the following piece of code:

-------------- start code ----------------
import numpy

def generic_func(A,B):
return numpy.dot(A,B)

A = numpy.ones((2,2))
B = [1,2]
C = generic_func(A,B)
D = generic_func(A,B)

-------------- end code ----------------

This is a rather generic code that can operate on `array_like` objects.
Since `list` does not have a dot method, the use of A.dot(B) would be
less generic.

Wouldn't it be much more convenient if `numpy.dot` were designed such
that  `A` could also be a sparse matrix

regards,
Sebastian

On Sun, Nov 28, 2010 at 4:32 PM, Gael Varoquaux
<gael.varoquaux@normalesup.org> wrote:
> On Sun, Nov 28, 2010 at 03:16:19PM +0000, Pauli Virtanen wrote:
>> However, I believe 'dot' should be left to be there. `ndarrays` recently
>> gained the same method for matrix products, so it makes sense to leave it
>> be also for sparse matrices. This has also the advantage that it becomes
>> possible to write generic code that works both on sparse matrices and on
>> ndarrays.
>
>> So unless objections arise, the 'dot' method will be un-deprecated in 0.9.
>
> +1
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
```