In [1]:
import numpy as np
from scipy.sparse import csr_matrix
In [2]:
a = np.eye(1000, dtype=np.int64)
print(type(a))
In [3]:
print(a[:10, :10])
In [4]:
print(a.shape)
In [5]:
csr = csr_matrix(a)
print(type(csr))
In [6]:
def get_size_of_csr(csr):
return csr.data.nbytes + csr.indices.nbytes + csr.indptr.nbytes
In [7]:
print(a.nbytes)
In [8]:
print(get_size_of_csr(csr))
In [9]:
%%timeit
a @ a
In [10]:
%%timeit
csr * csr
In [11]:
a_dense = np.random.randint(1, 100, (1000, 1000))
csr_dense = csr_matrix(a_dense)
In [12]:
print(a_dense[:10, :10])
In [13]:
print(a_dense.dtype)
In [14]:
print(a_dense.shape)
In [15]:
print(a_dense.nbytes)
In [16]:
print(get_size_of_csr(csr_dense))
In [17]:
%%timeit
a_dense @ a_dense
In [18]:
%%timeit
csr_dense * csr_dense
In [19]:
a_10_10 = np.eye(10, dtype=np.int64)
csr_10_10 = csr_matrix(a_10_10)
In [20]:
print(a_10_10.nbytes)
In [21]:
print(get_size_of_csr(csr_10_10))
In [22]:
%%timeit
a_10_10 @ a_10_10
In [23]:
%%timeit
csr_10_10 * csr_10_10
In [24]:
a_100_100 = np.eye(100, dtype=np.int64)
csr_100_100 = csr_matrix(a_100_100)
In [25]:
print(a_100_100.nbytes)
In [26]:
print(get_size_of_csr(csr_100_100))
In [27]:
%%timeit
a_100_100 @ a_100_100
In [28]:
%%timeit
csr_100_100 * csr_100_100
In [29]:
a_200_200 = np.eye(200, dtype=np.int64)
csr_200_200 = csr_matrix(a_200_200)
In [30]:
print(a_200_200.nbytes)
In [31]:
print(get_size_of_csr(csr_200_200))
In [32]:
%%timeit
a_200_200 @ a_200_200
In [33]:
%%timeit
csr_200_200 * csr_200_200