Given the code snippet:
B = A @ M - T
where A
is a CSR scipy sparse matrix, M
and T
are two numpy arrays.
Question: During the matrix operations, does numpy treat A
as a dense matrix, or M
and T
as two sparse matrices?
I suspect that the latter case is true since the resulting matrix B
is not in the sparse format.
I also notices that this operation is much slower if I change the format of A
to dense, which sort of contradicts my guess.
A
the sparse matrix controls the operation. It does one thing if the other object is sparse, another if dense (with different result type) – hpaulj@
like*
passes the task tosparse.__mul__
, which in turn calls one of several methods depending on what theother
is. Follow the[source]
link on this page if you want more details: docs.scipy.org/doc/scipy/reference/generated/… – hpaulj