+ 2

What the difference between Python lists and NumPy arrays?

I guess the difference is numpy functions that you can apply to np.array. But I'm not sure. Please help!

29th Jul 2019, 4:10 AM
just trying to think
just trying to think - avatar
4 Answers
+ 3
Numpy elements have to be the same type; Due fact that Numpy is written in.C, there are significant difference in code execusion. Numpy arrays are simply much faster than typical Python lists when you operate on them
29th Jul 2019, 6:55 PM
Bartek Sobura
Bartek Sobura - avatar
+ 2
One important difference, all elements in a numpy array must be of the same type. In a list you can do this: l = [1, "car", 1.34] In numpy array you can't.
29th Jul 2019, 5:07 AM
Paul
Paul - avatar
+ 2
As far as my knowledge goes, numpy arrays are homogeneous array in memory like vectors in C++. This makes look up very fast and cpu-cache friendly.
31st Jul 2019, 11:00 PM
Mateusz R
Mateusz R - avatar
+ 1
Numpy has some handy ways to filter or operate the array. nparray * 5 #Multiplies each element in the array by 5. nparray[nparray!=0] #Filters each element, that is not equal to 0. But those can all be done with the map and filter functions on lists.
29th Jul 2019, 10:00 AM
Seb TheS
Seb TheS - avatar