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.

Start Free Trial

No credit card required