I have a .npz file which I want to load into RAM . The compressed file size is 30MB . I am doing the following operation to load the data into RAM.
import numpy as np
from scipy import sparse
from sys import getsizeof
a = sparse.load_npz('compressed/CRS.npz').todense()
getsizeof(a)
# 136
type(a)
# numpy.matrixlib.defmatrix.matrix
b = np.array(a)
getsizeof(b)
# 64000112
type(b)
# numpy.ndarray
Why numpy.matrix object occupy very low memory size compared to numpy.arrray ? Both a and b have same dimension and data.
.toarray()you'd have gotten the full size..todenseadds aasmatrixlayer on top of that, creating a view. That is an implementation detail. In generalgetsizeofis not a reliable measure. It sort of works with arrays, but is worthless with lists.