Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NumPy and List
#1
Is NumPy is better than Python list?
Reply
#2
Depends on the use case, use the right tool for the right job.
Reply
#3
Hello,
Answering to your question-
NumPy is a Python package, which has made its place in the world of scientific computing. It can deal with large data sizes, and also has a powerful N-dimensional array object along with a set of advanced functions.

Yes, a NumPy array is better than a Python list. This is in the following ways:
  • It is more compact.
  • It is more convenient.
  • It Is more efficiently.
  • It is easier to read and write items with NumPy.
Reply
#4
(May-06-2019, 08:44 AM)dukoolsharma Wrote: Yes, a NumPy array is better than a Python list.
As per Yoriz, it certainly depends. Rarely is one thing entirely better than another in programming. Any additional complexity should be justified; if I saw in code review someone importing numpy when a regular Python list would be fine, I would call them out on it.
Reply
#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


Forum Jump:

User Panel Messages

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