[SciPy-user] dot behaviour with sparse matrix

Robin robince@gmail....
Wed Oct 1 11:20:19 CDT 2008

Not sure if this is a bug or not but it was certainly unexpected
behaviour for me.

I found that dot(dense,dense) works as expected
(ie dimensions (8,255),(255,8) -> (8,8))
and that dot(sparse,sparse) also works that way, producing a sparse result.

But dot(dense,sparse) gives an output with the same dimensions as the
dense input. Not sure why this is happening and I found it a bit
confusing. Is this a bug or inteded behaviour?

Actually I was just going through an example and I notice that
dot(csc_matrix, dense_matrix) raises a NotImplemented type - so
perhaps the other cases should also:

With A, B arrays:
In [29]: A.shape
Out[29]: (3, 5)
In [30]: B.shape
Out[30]: (5, 3)
In [31]: dot(A,B).shape
Out[31]: (3, 3)
In [32]: dot(sparse.csc_matrix(A),sparse.csc_matrix(B)).shape
Out[32]: (3, 3)
In [33]: dot(A,sparse.csc_matrix(B)).shape
Out[33]: (3, 5)
In [34]: dot(sparse.csc_matrix(A),B).shape
Out[34]: (5, 3)

with A,B dense matrices:
In [42]: A.shape
Out[42]: (3, 5)
In [43]: B.shape
Out[43]: (5, 3)
In [44]: dot(A,B).shape
Out[44]: (3, 3)
In [45]: dot(sparse.csc_matrix(A),sparse.csc_matrix(B)).shape
Out[45]: (3, 3)
In [46]: dot(A,sparse.csc_matrix(B)).shape
Out[46]: (3, 5)
In [47]: dot(sparse.csc_matrix(A),B).shape
AttributeError                            Traceback (most recent call last)

/Users/robince/<ipython console> in <module>()

AttributeError: 'NotImplementedType' object has no attribute 'shape'



More information about the SciPy-user mailing list