[Numpy-discussion] np.dot and scipy sparse matrices
Stéfan van der Walt
stefan@sun.ac...
Thu Nov 10 12:56:39 CST 2011
On Thu, Nov 10, 2011 at 10:45 AM, Peter Prettenhofer
<peter.prettenhofer@gmail.com> wrote:
>> I don't know if np.dot is supposed to know anything about sparse
>> matrices; if so, then a fancier change may be needed.
>
> Ok, then I'll pass that on to the (sparse) scipy folks.
> Are there any alternative to np.dot you are aware of?
With sparse matrices, you can simply do
S = ss.csr_matrix(np.arange(9).reshape((3,3)))
x = np.array([[1],[1],[1]])
print S * x
[[ 6.]
[ 15.]
[ 24.]]
But I assume what you want is an easy way to handle both sparse
matrices and dense arrays with the same call? I noticed in your
comment on the sklearn list that this used to work on older versions
of numpy. If that is the case, this is probably a regression that
needs to be fixed.
Regards
Stéfan
More information about the NumPy-Discussion
mailing list