linalg.norm missing an 'axis' kwarg?!
![](https://secure.gravatar.com/avatar/d5aa64affb55c3d87e1f4d675ee483f0.jpg?s=120&d=mm&r=g)
Hi, I have a 2D matrix comprising a sequence of vectors, and I want to compute the norm of each vector. np.linalg.norm seems to be the best bet, but it does not support axis. Wouldn't this be a nice feature? Greetings, Hans
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
2009/2/9 Hans Meine <meine@informatik.uni-hamburg.de>:
I often work with vectors inside an array, so I would find it useful (even if it is just a two-line wrapper). I'd also add an "out" argument, so that the signature is similar to that of max, min, etc. norm(a, ord=None, axis=None, out=None) Cheers Stéfan
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On 11/20/2008 5:11 AM Hans Meine apparently wrote:
Of possible use until then: http://docs.scipy.org/doc/numpy/reference/generated/numpy.apply_along_axis.h... Alan Isaac
![](https://secure.gravatar.com/avatar/6ad429ea6ec37e1476a8ac3ad75c0d86.jpg?s=120&d=mm&r=g)
Am 20.11.2008 um 11:11 schrieb Hans Meine:
Hi, i usually do something like this: a = random.rand(3000) a.resize((1000,3)) vec_norms = sqrt(sum(a**2,axis=1)) It is much faster than apply_along_axis: %timeit apply_along_axis(linalg.norm,1,a) 10 loops, best of 3: 45.3 ms per loop %timeit sqrt(sum(a**2,axis=1)) 10000 loops, best of 3: 108 µs per loop The results are the same: sum(apply_along_axis(linalg.norm,1,a)- sqrt(sum(a**2,axis=1))) 0.0 Regards, Markus
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
Hi Hans 2009/2/10 Hans Meine <meine@informatik.uni-hamburg.de>:
If you look at the patch I posted (OK, that was some weeks ago, so I'll attach it again for your convenience), that's (more or less) exactly what I proposed.
Would you mind adding some tests to the patch? Cheers Stéfan
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
2009/2/9 Hans Meine <meine@informatik.uni-hamburg.de>:
I often work with vectors inside an array, so I would find it useful (even if it is just a two-line wrapper). I'd also add an "out" argument, so that the signature is similar to that of max, min, etc. norm(a, ord=None, axis=None, out=None) Cheers Stéfan
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On 11/20/2008 5:11 AM Hans Meine apparently wrote:
Of possible use until then: http://docs.scipy.org/doc/numpy/reference/generated/numpy.apply_along_axis.h... Alan Isaac
![](https://secure.gravatar.com/avatar/6ad429ea6ec37e1476a8ac3ad75c0d86.jpg?s=120&d=mm&r=g)
Am 20.11.2008 um 11:11 schrieb Hans Meine:
Hi, i usually do something like this: a = random.rand(3000) a.resize((1000,3)) vec_norms = sqrt(sum(a**2,axis=1)) It is much faster than apply_along_axis: %timeit apply_along_axis(linalg.norm,1,a) 10 loops, best of 3: 45.3 ms per loop %timeit sqrt(sum(a**2,axis=1)) 10000 loops, best of 3: 108 µs per loop The results are the same: sum(apply_along_axis(linalg.norm,1,a)- sqrt(sum(a**2,axis=1))) 0.0 Regards, Markus
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
Hi Hans 2009/2/10 Hans Meine <meine@informatik.uni-hamburg.de>:
If you look at the patch I posted (OK, that was some weeks ago, so I'll attach it again for your convenience), that's (more or less) exactly what I proposed.
Would you mind adding some tests to the patch? Cheers Stéfan
participants (4)
-
Alan G Isaac
-
Hans Meine
-
Markus Rosenstihl
-
Stéfan van der Walt