0 / 34
Lesson 1

Your First Array

NumPy is Python's core library for numerical computing. Its superpower is the ndarray β€” a fast, flexible container for grids of numbers.

While Python lists are general-purpose, NumPy arrays are optimized for math. They're faster, use less memory, and support element-wise operations out of the box.

Creating arrays

import numpy as np

a = np.array([1, 2, 3])
b = np.array([4.0, 5.0, 6.0])

Every NumPy journey starts with import numpy as np. This is the universal convention.

Why this matters

Almost every data and ML workflow eventually becomes arrays of numbers. pandas, scikit-learn, and PyTorch all lean on NumPy; understanding ndarray first is what makes those tools feel predictable instead of magical.

Diagram comparing a Python list of separate boxed numbers with one contiguous NumPy array block for vectorized math.
Lists scatter objects in memory; ndarrays pack one dtype in a single buffer.
  • Speed: Python for loops are slow; NumPy pushes work into C.
  • Semantics: arr * 2 multiplies every elementβ€”no manual indexing.
ResourcesDocs, references & more β€” opens in a new tab
🎯 Your Task

Create a NumPy array called arr containing [10, 20, 30, 40, 50] and print it.

arr = np.array([10, 20, 30, 40, 50])
exercise.py
⌘⏎ run Β· βŒ˜β† β†’ nav
β–Ά Output
Run your code to see output here.