Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NumPy and List
#5
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).
Reply


Messages In This Thread
NumPy and List - by karansingh - May-06-2019, 07:25 AM
RE: NumPy and List - by Yoriz - May-06-2019, 08:39 AM
RE: NumPy and List - by dukoolsharma - May-06-2019, 08:44 AM
RE: NumPy and List - by micseydel - May-10-2019, 09:25 PM
RE: NumPy and List - by scidam - May-11-2019, 02:25 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020