Lesson 1 of 15
Vector Projection
Vector Projection
The projection of v onto u is the component of v that lies in the direction of u:
The scalar coefficient scales u to exactly the "shadow" of v along u.
Geometric Intuition
Imagine shining a light perpendicular to u — the shadow of v cast onto the line through u is exactly the projection. The perpendicular component is orthogonal to u.
Examples
| v | u | proj_u(v) |
|---|---|---|
| [3, 4, 0] | [1, 0, 0] | [3.0000, 0.0000, 0.0000] |
| [1, 2, 3] | [1, 1, 1] | [2.0000, 2.0000, 2.0000] |
| [0, 5] | [3, 4] | [2.4000, 3.2000] |
Note: For [1,2,3] onto [1,1,1]: the sum is 6, so the coefficient is , giving [2, 2, 2].
Your Task
Implement dot(a, b) returning the dot product of two vectors, and project(v, u) returning the projection of v onto u.
Python runtime loading...
Loading...
Click "Run" to execute your code.