+ 2

CSR matrices multiplication

I have two sparse matrices, I need to bring them both to the CSR (Compressed Sparse Row) format and then multiply. But I also tried to first multiply the regular matrices and only then bring the result of this multiplication to the CSR format. And in the end I get dirrefent results. Why? Could someone pls explain? Here's my code: import numpy as np from scipy.sparse import csr_matrix np.random.seed(42) J = np.eye(5) J[4,:] = np.random.randint(low=0, high=4, size = (5)) K = np.eye(5) K[2,:] = np.random.randint(low=0, high=4, size = (5)) print(J) print('\n') print(K) Z = csr_matrix(J@K) print('\n') print(Z) F = csr_matrix(J) H = csr_matrix(K) print('\n') print(F@H)

26th Nov 2023, 8:40 PM
Dimitry Buylin
Dimitry Buylin - avatar
1 Odpowiedź
+ 2
oh, seems like I found the answer! :D I wasn't attentive enough. The result is technically same, the order of representation is different though.
26th Nov 2023, 8:49 PM
Dimitry Buylin
Dimitry Buylin - avatar