import numpy as np
from scipy.sparse import csr_matrix
row = np.array([0, 0, 1, 1, 2, 2])
col = np.array([0, 2, 1, 2, 0, 1])
data = np.array([1, 1, 1, 1, 1, 1])
sparseA=csr_matrix((data, (row, col)), shape=(3, 3))
print("sparseA=")
print(sparseA)
arrA=sparseA.toarray()
print("arrA=")
print(arrA)
sparseA=
(0, 0) 1
(0, 2) 1
(1, 1) 1
(1, 2) 1
(2, 0) 1
(2, 1) 1
arrA=
[[1 0 1]
[0 1 1]
[1 1 0]]
row = np.array([0, 0, 1, 1, 2, 2])
col = np.array([0, 2, 1, 2, 0, 1])
data = np.array([2, 2, 2, 2, 2, 2])
sparseB=csr_matrix((data, (row, col)), shape=(3, 3))
print("sparseB=")
print(sparseB)
arrB=sparseB.toarray()
print("arrB=")
print(arrB)
sparseB=
(0, 0) 2
(0, 2) 2
(1, 1) 2
(1, 2) 2
(2, 0) 2
(2, 1) 2
arrB=
[[2 0 2]
[0 2 2]
[2 2 0]]
sparseC= sparseA @ sparseB
print("sparseC=")
print(sparseC)
arrC=sparseC.toarray()
print("arrC=")
print(arrC)
sparseC=
(0, 1) 2
(0, 2) 2
(0, 0) 4
(1, 0) 2
(1, 2) 2
(1, 1) 4
(2, 1) 2
(2, 2) 4
(2, 0) 2
arrC=
[[4 2 2]
[2 4 2]
[2 2 4]]