O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Broadcasting

So far, we have worked with two arrays with equal shape. In fact, this is not necessary. While we cannot necessarily add two arrays of any shape, there are situations where we can reasonably perform an arithmetic operation on arrays of different shapes. In some sense, information in a smaller array is treated as if it belongs to an array of equal shapes, but with repeated values. Let's see some of this broadcasting behavior in action.

Now, recall that the array arr1 is 3 x 3 x 3; that is, it has three rows, three columns, and three slabs. Here, we create an object, arr3:

This object has the shape (1, 1, 3). So, this object has ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required