Skip to content

Instantly share code, notes, and snippets.

@evu
Last active April 17, 2019 00:13
Show Gist options
  • Save evu/408f6455c2e5ba65542aacae61c2a0ba to your computer and use it in GitHub Desktop.
Save evu/408f6455c2e5ba65542aacae61c2a0ba to your computer and use it in GitHub Desktop.
L2 norm
import numpy as np
def l2_norm(vec):
return np.sqrt(np.square(vec).sum())
def test_l2_norm():
for _ in range(1000):
ref = np.random.rand(100, 1)
ref_norm = np.linalg.norm(ref)
norm = l2_norm(ref)
assert np.allclose(ref_norm, norm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment