NumPy is the foundation of Python's data tools.
Direct answer
NumPy provides the ndarray, a fast array that supports maths on whole arrays without loops. It underpins pandas, scikit-learn and many other data libraries. Learn how to create arrays, slice them and use functions like mean and sum.
Basics
import numpy as np
a = np.array([1, 2, 3, 4])
print(a * 2) # [2 4 6 8]
print(a.mean()) # 2.5
m = np.array([[1, 2, 3], [4, 5, 6]])
print(m.shape) # (2, 3)
print(m[0, 1]) # 2
print(m[:, 1]) # [2 5]
print(m.reshape(3, 2))
Handy functions
| Function | Purpose |
|---|---|
np.arange(0, 10, 2) | range of numbers |
np.zeros((2, 3)) | array of zeros |
np.random.rand(3) | random numbers |
a.sum(), a.max() | summaries |
Boolean filtering
a = np.array([5, 12, 7, 20])
print(a[a > 6]) # [12 7 20]
Where Teyro fits
Teyro's Data Science for Beginners course turns this into short lessons you can play in a few minutes a day. It has 50 lessons, and you can start free.
The bottom line
Think in arrays, not loops.



