Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-373

L2 Normalize Embedding Vector

Problem

L2 normalization divides a vector by its Euclidean norm, leaving the zero vector unchanged.

Given the vector, return the normalized vector.

Hint

Guard the zero vector case.

Test cases

case 1
in: [[3,4]]
expected: [0.6,0.8]
case 2
in: [[1,0]]
expected: [1,0]
case 3
in: [[0,0]]
expected: [0,0]
Starter codePython
def l2_normalize_vector(vector):
    # Your code here
    pass

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