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

No credit card required

Time for action – adding vectors

Imagine that we want to add two vectors called `a` and `b` (see https://www.khanacademy.org/science/physics/one-dimensional-motion/displacement-velocity-time/v/introduction-to-vectors-and-scalars). Vector is used here in the mathematical sense meaning a one-dimensional array. We will learn in Chapter 5, Working with Matrices and ufuncs, about specialized NumPy arrays, which represent matrices. Vector `a` holds the squares of integers `0` to n, for instance, if `n` is equal to `3`, then a is equal to `(0,1, 4)`. Vector `b` holds the cubes of integers `0` to n, so if `n` is equal to `3`, then `b` is equal to `(0,1, 8)`. How will you do that using plain Python? After we come up with a solution, we will compare it to the NumPy equivalent.

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

No credit card required