Learnr

Learn NumPy

Arrays, broadcasting and vectorized math, the base of Python data work.

or browse all courses.

Free to start. Built from a single prompt. No credit card.

NumPy is the Python library for fast numerical arrays, and it sits underneath pandas, scikit-learn, Matplotlib and much of scientific Python. Its core object, the ndarray, holds values of one data type in a grid of any number of dimensions, and operations run in compiled code instead of Python loops. Learning NumPy means learning to think in whole arrays: shapes and axes, slicing and boolean masks, broadcasting, and vectorized functions that replace explicit loops. Learnr builds a NumPy course at your pace, with short lessons that each center on one idea and a snippet you can try right away.

How to learn NumPy, step by step

  1. Create arrays and inspect them. Use np.array, np.arange, np.linspace, np.zeros and np.ones, and print shape, ndim and dtype for each. Knowing these three attributes at all times is the foundation for every operation that follows.
  2. Master indexing in two dimensions. Practice row and column slices, negative indices, step slicing and boolean masks like arr[arr > 0]. Learn that basic slices return views that share memory, while fancy indexing returns copies, a common source of surprises.
  3. Replace loops with vectorized expressions. Take a loop that computes something per element and rewrite it as one array expression using ufuncs like np.exp and np.where. Time both versions with %timeit to feel why vectorization matters.
  4. Learn broadcasting with shape diagrams. Write shapes side by side, align them from the right and check each dimension is equal or 1. Subtracting column means from a matrix, shape (n, m) minus (m,), is the classic first example worth mastering.
  5. Get comfortable with axis and reshape. Compute sums, means and argmax along axis=0 and axis=1 and predict the output shape before running it. Use reshape, newaxis and transpose to prepare arrays. Brief Learnr reviews help axis rules stick between sessions.
  6. Apply it to a small numeric project. Implement linear regression with the @ operator and np.linalg.lstsq, or simulate dice with np.random.default_rng. A self-contained project ties indexing, broadcasting and aggregation together in one place.

What you'll learn

  • Create arrays and reason about shape, dtype and number of dimensions
  • Select data with slicing, boolean masks and integer array indexing
  • Apply broadcasting rules to combine arrays of different shapes
  • Replace Python loops with vectorized operations and aggregations along an axis
  • Perform matrix multiplication and basic linear algebra with numpy.linalg

What's inside your NumPy course

A sample path Learnr builds for NumPy. Your real course adapts to your goal and level.

  • 1. The ndarray: shape, dtype and creation
  • 2. Indexing, slicing and boolean masks
  • 3. Vectorized math and universal functions
  • 4. Broadcasting rules
  • 5. Aggregations, axes and reshaping
  • 6. Linear algebra and random numbers

How long does it take to learn NumPy?

With basic Python, the core of NumPy takes about 2 to 4 weeks at 3 to 5 hours a week. Thinking naturally in vectorized operations and broadcasting comes with a couple of months of regular use in data or science work.

What you need before you start

Basic Python: variables, lists, loops and functions. High school algebra helps, and some linear algebra makes matrix operations more meaningful.

Common mistakes to avoid

  • Writing Python for loops over array elements, which throws away the speed NumPy exists to provide. Look for a vectorized function first.
  • Modifying a slice and being surprised the original changed. Slices are views, so call .copy() when you need independent data.
  • Confusing the * operator with matrix multiplication. In NumPy, * is element-wise, and @ or np.matmul performs matrix products.

How Learnr builds your course

Type your topic

Tell Learnr you want to learn NumPy, or get as specific as you like.

Get a personalized course

Learnr instantly builds a full NumPy course tailored to your goal and skill level.

Learn and level up

Move through bite-sized lessons and interactive practice, earning XP and keeping your streak.

NumPy questions, answered

Should I learn NumPy before pandas?

A little NumPy first helps, because pandas columns are built on arrays and share ideas like vectorization and boolean masks. You do not need to master it before starting pandas.

What is broadcasting in NumPy?

Broadcasting is how NumPy combines arrays of different shapes by virtually stretching dimensions of size 1, aligned from the right. It lets you, for example, add a row vector to every row of a matrix without copying data.

Explore more courses

More data and ai courses

See all data and ai courses

Ready to learn NumPy?

Start your free, personalized NumPy course in seconds. .