Thuta Learning
BasicData & Databasesintermediate

What is Numpy?

Relax. We'll talk through this in plain words — no textbook voice.

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.

python
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.

You should see
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.

Easy traps

  • If you run import numpy as np without installing NumPy first, you'll get a ModuleNotFoundError. Check the Setup lesson and install it.

Exercise

In the real world, NumPy gets used a lot for storing numeric data — sales amounts, exam marks, sensor readings, image pixels, and the like — as arrays so you can compute over all of it at once.

You'll know it worked when: