Lp-norm without using any python library

325 Views Asked by At

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
1

There are 1 best solutions below

0
On BEST ANSWER

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)