Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-293

Unit Vector Check

Problem

Check whether a vector has unit length.

Return True when the squared norm is within 1e-9 of 1. The zero vector and any non-unit vector return False.

Hint

Compare the squared norm to 1; this avoids computing a square root.

Test cases

case 1
in: [[1,0,0]]
expected: true
case 2
in: [[0.6,0.8]]
expected: true
case 3
in: [[0,0]]
expected: false
case 4
in: [[1,1]]
expected: false
case 5
in: [[0.6,0.8000000001]]
expected: true
Starter codePython
def unit_vector_check(v):
    # Your code here
    pass

5 test cases · run your code against them in the editor