Answer the question
In order to leave comments, you need to log in
Why do we need NumPy arrays if Python has its own lists?
Actually the question is in the title.
It is not clear why NumPy developed a separate type of arrays, because Python has lists that store information in the same way.
Answer the question
In order to leave comments, you need to log in
The following analogy is appropriate here: here is an apple tree (you know about trees, right?), A pear tree stalk was grafted onto it .
NumPy arrays are not native, but perfectly grafted to python wrappers over C-arrays used inside the BLAS core of the NumPy library.
They, these arrays, contain the primitive data types of the C language - int, double, etc.
A Python leaf is an array of Python objects . Although some of them have the same name as C primitive data types (like int), they are different. They even have different memory sizes - 4 bytes for C-int and from 24 bytes (and for numbers over 2**30 - even more) for python-int ( link ).
The differences are not limited to this, but this is enough) ps pay attention to Timur Barbashov
's answer - he lies like a gray gelding. The implementation of the list type lies in a file with the expressive name arraymodule.c .
Numpy arrays consume less memory and operations with them are faster.
Lists are very different in structure from arrays. Considering that you have reached NumPy, you should at least roughly imagine this. Well, NumPy is designed for fast data processing, so lists don’t roll there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question