Sometimes numpy works slower than native python lists, e.g.
when appending the data to existing arrays
import numpy as np
x = np.array(list())
y = list()
%timeit -n 100000 np.append(x, '2')
Output:
10.5 µs ± 1.1 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit -n 100000 y.append('2')
Output:
108 ns ± 4.11 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
The same behavior is true when working with big arrays.
Numpy is a good choice when you need to perform element-wise operations over arrays. Having a lot of
functions and nd-array-arithmetic operations implemented in C, numpy allows to avoid slow python loops when working with arrays (in general, it invokes loops implemented in C under the hood).