3

NumPy Arrays Quiz

Last Update Unknown

NumPy Arrays Revision Quiz

How do you implement the vector subtraction between vector u and vector v?

Reveal Answer

u - v and the resulting vector is [1, -1]

Multiply the numpy array z with the scalar -2:

Reveal Answer

-2 * z and the resulting vector is [-4, -8]

Consider the lists [1, 2, 3, 4, 5] and [1, 0, 1, 0, 1], and cast both lists to a NumPy array then multiply them together. Is the result a scalar or a vector?

Reveal Answer

a = np.array([1, 2, 3, 4, 5])
b = np.array([1, 0, 1, 0, 1])

a * b and the resulting vector is [1, 0, 3, 0, 5]

Convert the list [1, 0] and [0, 1] to numpy arrays a and b. Then, find the dot product. Is the result a scalar or a vector?

Reveal Answer

The dot product is 0 which is a scalar

Convert the list [1, 1] and [0, 1] to numpy arrays a and b. Then find the dot product. Is the result a scalar or a vector?

Reveal Answer

The dot product is 1 which is a scalar

Why are the results of the dot product for [-1, 1] and [1, 1] and the dot product for [1, 0] and [0, 1] zero, but not zero for the dot product for [1, 1] and [0, 1]?

Hint: plot the arrays as vectors in a 2D space.

Reveal Answer

The vectors used for question 4 and 5 are perpendicular. As a result, the dot product is zero.