'Lp-norm without using any python library
How do you find Lp-norm without using any python library?
def norm(vec, p):
# p is scalar
# where vec is a vector in list type
pass
Solution 1:[1]
Using numpy for instance would be more efficient, but with bare python you can do:
def norm(vec, p):
return sum([i**p for i in vec])**(1/p)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ziur Olpa |
