The dot product of two equal-length 1-D arrays x and y of length n is defined algebraically as:
x⋅y=i=1∑nxiyi=x1y1+x2y2+⋯+xnynand geometrically as:
x⋅y=∥x∥⋅∥y∥⋅cos(θ)where ∥x∥ and ∥y∥ are the magnitudes of x and y, and θ is the angle between them.
Return the dot product as a scalar float.
Input: x = [1,2,3], y = [4,5,6]
Output: 32.0
1×4 + 2×5 + 3×6 = 4 + 10 + 18 = 32
Input: x = [1,0], y = [0,1]
Output: 0.0
Orthogonal vectors (perpendicular)
Input: x = [-1,2], y = [3,-1]
Output: -5.0
(-1)×3 + 2×(-1) = -3 + (-2) = -5
Convert inputs to NumPy arrays first, then use vectorized operations.
NumPy has a built-in function for this: np.dot(x, y).
Sign in to take notes on this problem
Accepts: array
Accepts: array
The dot product of two equal-length 1-D arrays x and y of length n is defined algebraically as:
x⋅y=i=1∑nxiyi=x1y1+x2y2+⋯+xnynand geometrically as:
x⋅y=∥x∥⋅∥y∥⋅cos(θ)where ∥x∥ and ∥y∥ are the magnitudes of x and y, and θ is the angle between them.
Return the dot product as a scalar float.
Input: x = [1,2,3], y = [4,5,6]
Output: 32.0
1×4 + 2×5 + 3×6 = 4 + 10 + 18 = 32
Input: x = [1,0], y = [0,1]
Output: 0.0
Orthogonal vectors (perpendicular)
Input: x = [-1,2], y = [3,-1]
Output: -5.0
(-1)×3 + 2×(-1) = -3 + (-2) = -5
Convert inputs to NumPy arrays first, then use vectorized operations.
NumPy has a built-in function for this: np.dot(x, y).
Sign in to take notes on this problem
Accepts: array
Accepts: array