Re: [Numpy-discussion] efficient norm of a vector

2007-03-14 Thread lorenzo bolla
thanks. I hadn't seen it. anyway, from very rough benchmarks I did, the quickest and easiest way of computing the euclidean norm of a 1D array is: n = sqrt(dot(x,x.conj())) much faster than: n = sqrt(sum(abs(x)**2)) and much much faster than: n = scipy.linalg.norm(x) regards, lorenzo. On 3/14/

Re: [Numpy-discussion] efficient norm of a vector

2007-03-13 Thread Bill Baxter
There is numpy.linalg.norm. Here's what it does: def norm(x, ord=None): x = asarray(x) nd = len(x.shape) if ord is None: # check the default case first and handle it immediately return sqrt(add.reduce((x.conj() * x).ravel().real)) if nd == 1: if ord == Inf:

[Numpy-discussion] efficient norm of a vector

2007-03-13 Thread lorenzo bolla
Hi all, just a quick (and easy?) question. what is the best (fastest) way to implement the euclidean norm of a vector, i.e. the function: import scipy as S def norm(x): """normalize a vector.""" return S.sqrt(S.sum(S.absolute(x)**2)) ? thanks in advance, Lorenzo. ___