NumPy is a widely-used library for crunching numerical data fast in Python. Its core offering is an array object called ndarray. A Python list can store data too, but you usually end up looping through each item one at a time. A NumPy array, on the other hand, can operate on a whole batch of data at once — making it cleaner, faster, and just more effective to work with.
import numpy as np
# A standard Python list
my_list = [1, 2, 3]
# A NumPy array
my_array = np.array([1, 2, 3])
print("Python list:", my_list)
print("NumPy array:", my_array)
print("Array plus 10:", my_array + 10)In this code, import numpy as np imports NumPy under the short name np. np.array() converts a Python list into a NumPy array. On the last line you'll see 10 added to every element in the array. Doing my_list + 10 on a plain Python list would likely throw an error, but a NumPy array applies the numerical operation across every element.
Python list: [1, 2, 3] NumPy array: [1 2 3] Array plus 10: [11 12 13]Info
When you print a NumPy array, you may notice it shows up without commas, like [1 2 3]. That's your sign it's an array, not a list.