0

In this question Why NumPy instead of Python lists? [closed] every one seems to agree than numpy array are a more compact structure. I try to replicate this and I found than is only true when the list become huge. I am on python3.5 ubuntu 12.04

import sys
from numpy getsizeof

a = [1.0,2.0,3.0,4.0]
print(getsizeof(a))  # 96
print(getsizeof(numpy.array(a)))  # 128

a = list(range(1000))
print(getsizeof(a))  # 9112
print(getsizeof(numpy.array(a)))  # 8096

Could someone explain me why?

5

1 Answer 1

3

Fixed overhead. Both lists and numpy arrays have a fixed-size data structure that is used to manage the data in the container. Numpy has a slightly larger structure, which the more compact value storage doesn't immediately overcome.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.