[Numpy-discussion] normalizing a vector so it has magnitude 1
SimonPalmer
simon.palmer@gmail....
Wed Aug 27 17:00:06 CDT 2008
sorry, 1D array
this is perfect, thanks.
On Aug 27, 10:18 pm, Gary Ruben <gru...@bigpond.net.au> wrote:
> I don't know what you mean by a 1D vector, but for a 3-vector, you can
> do this (also works for N-dimensions)
>
> In [1]: a=r_[1.,2.,3.]
> In [2]: a
> Out[2]: array([ 1., 2., 3.])
> In [3]: b=a/norm(a)
> In [4]: b
> Out[4]: array([ 0.26726124, 0.53452248, 0.80178373])
>
> Gary R
>
> > bit of a newb question, is there a method for normalising a 1D vector
> > so it ends up with magnitude 1?
>
> > I can do it manually but I was hoping there was a neat numpy - or
> > scipy - trick. I've been web surfing but nothing really leaps out
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list