Last active
April 17, 2019 00:13
-
-
Save evu/408f6455c2e5ba65542aacae61c2a0ba to your computer and use it in GitHub Desktop.
L2 norm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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