RAG and Vector Search · Exercise 1 of 5Next
Beginner
Length, normalise and check
Write length(v): the square root of the sum of the squares of the numbers in v.
Write normalise(v): a new list scaled to length 1. A vector of all zeros cannot be scaled, so return a list of zeros of the same size instead of failing.
Write is_unit(v, tolerance=0.001): True when the length of v is within tolerance of 1.
What Check tests
lengthis the Euclidean lengthnormalisescales to length 1normalisedoes not change its input- A zero vector gives zeros, not an error
is_unittells unit from non-unit vectors
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.