Compute the dot product of two equal-length vectors:
x⋅y=i=1∑nxiyiHere, xi and yi are corresponding vector elements and n is their shared length. Return the result as a Python float.
Input: x = [1, 2, 3], y = [4, 5, 6]
Output: 32.0
Explanation: The products 4, 10, and 18 sum to 32.
Input: x = [1, 0], y = [0, 1]
Output: 0.0
Input: x = [-1, 2], y = [3, -1]
Output: -5.0
Convert both vectors with np.asarray(..., dtype=float).
Use np.dot(x, y) and convert the NumPy scalar to float.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Compute the dot product of two equal-length vectors:
x⋅y=i=1∑nxiyiHere, xi and yi are corresponding vector elements and n is their shared length. Return the result as a Python float.
Input: x = [1, 2, 3], y = [4, 5, 6]
Output: 32.0
Explanation: The products 4, 10, and 18 sum to 32.
Input: x = [1, 0], y = [0, 1]
Output: 0.0
Input: x = [-1, 2], y = [3, -1]
Output: -5.0
Convert both vectors with np.asarray(..., dtype=float).
Use np.dot(x, y) and convert the NumPy scalar to float.
Sign in to take notes on this problem
Accepts: array
Accepts: array