2018-10-03 18:59:01 +00:00
|
|
|
# http://stackoverflow.com/questions/7741878/how-to-apply-numpy-linalg-norm-to-each-row-of-a-matrix/7741976#7741976
|
|
|
|
# setup: import numpy as np ; N = 1000; x = np.random.rand(N,N)
|
|
|
|
# run: l2norm(x)
|
2018-04-05 22:07:33 +00:00
|
|
|
|
2018-10-03 18:59:01 +00:00
|
|
|
# pythran export l2norm(float64[][])
|
2018-04-05 22:07:33 +00:00
|
|
|
import numpy as np
|
2018-10-03 12:38:48 +00:00
|
|
|
|
|
|
|
|
2018-04-05 22:07:33 +00:00
|
|
|
def l2norm(x):
|
2018-10-03 12:38:48 +00:00
|
|
|
return np.sqrt(np.einsum('ij,ij->i', x, x))
|