In the previous lesson, we've learned that we can perform arithmetic operations between ndarrays of the same shape.

In this lesson, we will learn that these operations can also be performed between ndarrays of different shape, for as long as a set of rules is verified.

In particular, you'll:

  1. Learn how to perform arithmetic operations between ndarrays and values. For example, how to add a fixed value to each entry of an ndarray.
  2. Learn how to perform arithmetic operations between 1-dimensional arrays and 2-dimensional arrays.
  3. Learn how to change the shape of an ndarray.

Now, imagine that we want to increase every entry in an ndarray by one. How do we do that? In this lesson, we'll cover that and much more!

As with all Dataquest lessons, this is an interactive learning experience. You'll be writing real Python code and using NumPy in our browser-based coding environment so there's no setup and no obstacles between you and learning!

Objectives

  • Learn how to perform arithmetic operations between ndarrays and values.
  • Learn how to change the shape of an ndarray.

Lesson Outline

  1. Introduction
  2. Broadcasting with a Single Value
  3. Broadcasting Mental Model
  4. Broadcasting Horizontally
  5. Broadcasting Vertically
  6. Broadcasting on Both
  7. Broadcasting Rules
  8. Reshaping
  9. Compatible Shapes
  10. Next Steps