D
D
Drovosek012019-02-16 22:16:32
Python
Drovosek01, 2019-02-16 22:16:32

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

3 answer(s)
L
longclaps, 2019-02-17
@Drovosek01

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 .

S
Sergey Sokolov, 2019-02-16
@sergiks

Numpy arrays consume less memory and operations with them are faster.

M
Mikhail Makarov, 2019-02-16
@KevlarBeaver

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 question

Ask a Question

731 491 924 answers to any question