Reading the Python Data Science Handbook: NumPy Broadcasting

StonedApe
6 min readApr 23, 2021

So again, I’m basically trying to go through this Python Data Science Handbook in hopes of becoming quite familiar with the world of Data Science afterwards.

Not going to lie though, I’ve been “microdosing” some marijuana most of the time I read through a part of the book. Believe it or not, it actuallly works better than coffee sometimes for getting your brain focused, I mean as long as you’re not smoking a ton.

Don’t knock it until you try it.

Anyway, today I continued on the Numpy section of the book, and looked at the part of the section called Computation on Arrays: Broadcasting”.

What is Broadcasting

This is the exact definition from the book: “Broadcasting is simply a set of rules for applying binary ufuncs (e.g., addition, subtraction, multiplication, etc.) on arrays of different sizes.”

So basically, it’s a way for us to add, or subtract, or apply any other type of UFuncs, on arrays of different dimensions, like for example adding a 1-D array to a 2-D array.

The picture here below shows how two arrays of the same dimension size get added to one another. Basically just add the values on an element by element basis.

In this case, the 5 gets added to the 0, the second 5 gets added to the 1, and the last 5 gets added to the 2. Just adding along the columns in this example here.

--

--

StonedApe

A guy that smokes weed and learns stuff. Stay Trippy.