Skip to content
dreamcode
dreamcode
Map
NumPy arrays
Lesson 73 of 77
+15 XP on finish
PYTHON APPLIEDChapter 13 · Python for Data Science

NumPy arrays and vectorized math

NumPy is the foundation of scientific Python. Its ndarray stores homogeneous data in contiguous memory, enabling vectorized operations that run orders of magnitude faster than Python loops.

Worked example

How it reads

  • np.array([...]) creates a NumPy array from a Python list
  • **temps * 9 / 5 + 32** applies math to every element at once (vectorized)
  • .mean(), .max(), .std() compute statistics without loops
Cloud tip: NumPy arrays must contain elements of the same type (all ints or all floats). This constraint enables the speed gains.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Use a boolean mask to keep the altitudes above 3000, print that array, then print its mean.

Press Run to check your work.