[Numpy-discussion] Vector magnitude?

Gael Varoquaux gael.varoquaux@normalesup....
Wed Sep 5 12:20:45 CDT 2007


On Wed, Sep 05, 2007 at 11:55:36AM -0500, Robert Dailey wrote:
>    1) Is there any way in numpy to represent vectors? Currently I'm using
>    'array' for vectors.

What do you call a vector ? For me a vector is an element of an linear
space. In numerical methods what is comonly called a vector is a 1D array
of arbitrary length. I suspect you mean something different, given your
question

>    2) Is there a way to calculate the magnitude (length) of a vector in
>    numpy?

I am being dumb. What do you mean by magnitude (or length) ? Maybe it is
just because I am not a native English speaker. If you are talking about
the euclidien norm, I don't know a built in way of doing it, but it is
very easy to define a norm function:

import numpy as N

a = N.arange(3)
norm = lambda x: N.sqrt(N.square(x).sum())
norm(a)
-> 2.2360679775



More information about the Numpy-discussion mailing list