I have a CSR matrix :
>> print type(tfidf) <class 'scipy.sparse.csr.csr_matrix'>
I want to get a point product of two rows of this CSR matrix :
>> v1 = tfidf.getrow(1) >> v2 = tfidf.getrow(2) >> print type(v1) <class 'scipy.sparse.csr.csr_matrix'>
Both v1 and v2 are also CSR matrices. Therefore, I use the dot routine:
>> print v1.dot(v2) Traceback (most recent call last): File "cosine.py", line 10, in <module> print v1.dot(v2) File "/usr/lib/python2.7/dist-packages/scipy/sparse/base.py", line 211, in dot return self * other File "/usr/lib/python2.7/dist-packages/scipy/sparse/base.py", line 246, in __mul__ raise ValueError('dimension mismatch') ValueError: dimension mismatch
These are rows of the same matrix, therefore their parameters should correspond to:
>> print v1.shape (1, 4507) >> print v2.shape (1, 4507)
Why doesn't dot routine work?
Thanks.
source share