Skip to content
SamplePreview build: teacher profiles, ratings, reviews and lesson counts are sample data.
All tutors

NumPy Arrays from the Ground Up

Think in arrays: shapes, axes, broadcasting and vectorised maths, with embeddings as the running example.

By Felix Brandt Beginner Python for AI 4.5(2) 29 lessons taught Sample

Your first 3 replies from the tutor are free. Then you can continue the lesson for $4 from your credit.

A taste of a lesson

One question and the answer, as this tutor gives it.

NumPy Arrays from the Ground Up AI tutor following Felix Brandt's plan
Student:

I have embeddings with shape (1000, 384). How do I normalise each row?

Tutor:

Compute each row's length, then divide. norms = np.linalg.norm(E, axis=1, keepdims=True) gives shape (1000, 1): one length per row, kept as a column. Then E_norm = E / norms broadcasts that column across all 384 values in each row. Without keepdims you would get shape (1000,), and the division would fail because shapes are compared from the right. As a check, np.linalg.norm(E_norm, axis=1) should be all ones. What shape do you expect that check to return?

Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.

What you will be able to do

  • Create arrays and explain their shape, dtype and axes
  • Select data with slices, boolean masks and integer indexing
  • Predict when broadcasting works and what shape it produces
  • Replace Python loops with vectorised operations
  • Compute cosine similarities between embedding vectors

Lesson plan

6 lessons. Pick one to start there.

  1. 1 Arrays, shapes and dtypes Create arrays and read their shape, number of dimensions and dtype. Start
  2. 2 Indexing, slicing and masks Select rows, columns and values that meet a condition. Start
  3. 3 Axes and aggregations Use sum, mean, max and argmax along the right axis. Start
  4. 4 Broadcasting Combine arrays of different shapes and predict the result shape. Start
  5. 5 Vectorised thinking Rewrite loops as whole array operations and see the speed difference. Start
  6. 6 Embeddings and similarity Normalise embedding rows and rank items by cosine similarity to a query. Start

Try asking

Tap a question to start a lesson with it.

About this tutor

For beginners who can write Python loops and now meet NumPy in every AI tutorial. You learn what an array is, how shape, dtype and axis work, how indexing and boolean masks select data, how broadcasting combines arrays of different shapes, and why vectorised code is faster and clearer than loops. The running example is a small matrix of embeddings: you normalise rows, compute similarities with a dot product and find the closest items. Along the way you learn the traps: views versus copies, integer overflow and NaN values that spread through results.

Reviews

4.5

2 ratingsSample

  • Elif K.Sample

    Clear on views versus copies, which had burned me before. Wanted a bit more on 3D arrays but the basics are very solid.

  • Arjun S.Sample

    Writing shapes out by hand for broadcasting felt childish for a minute and then fixed every bug I had. The embedding similarity exercise tied it all together.

About the teacher

Felix Brandt

Numerical Python and code quality for data and AI projects that have outgrown a single notebook

9 tutors 4.5(18) 374 lessons taught Sample

I work on the part of AI projects nobody photographs: the arrays, dataframes, tests and packaging that let a prototype survive contact with real data. I came to this through scientific computing and later backend work, so I care about two things at once, getting the numbers right and keeping the code readable for the next person. My lessons are...

See Felix's profile and tutors