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.
Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.