All problems
Vector Projection
Problem
Project vector a onto vector b. Returns the projected vector (same direction as b).
proj_b(a) = (a·b / b·b) * b
If b is the zero vector, return a list of zeros with the same length as a.
Hint
The scalar projection is (a·b)/(b·b); multiply by b componentwise.
Test cases
case 1
in: [[3,4],[1,0]]
expected: [3,0]
case 2
in: [[1,2,3],[0,0,1]]
expected: [0,0,3]
case 3
in: [[2,2],[1,1]]
expected: [2,2]
case 4
in: [[1,1],[0,0]]
expected: [0,0]
Starter codePython
def project(a, b):
# Your code here
pass4 test cases · run your code against them in the editor