python - Why is there a large overhead in pickling numpy arrays? -


suppose have simple array in python:

>>> x = [1.0, 2.0, 3.0, 4.0] 

when pickled, reasonably small size:

>>> pickle.dumps(x).__len__() 44 

how come if use numpy array, size larger?

>>> xn = np.array(x) >>> pickle.dumps(xn).__len__() 187 

converting less precise data type helps little bit...

>>> x16 = xn.astype('float16') >>> pickle.dumps(x16).__len__() 163 

other numpy/scipy data structures sparse matrices don't pickle well. why?

checking in debugger, numpy array has fields max, min, type etc apart data, not sure python list has.

a complete list can found on http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

as pickling binary copying, these other fields being copied, resulting in larger size.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -