Re: [Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Ben Gamari
On Tue, 08 Feb 2011 18:06:48 +, Andrew Jaffe wrote: > For this shape=(N,3) vector, this is not what you mean: as Robert Kern > also has it you want axis=1, which produces a shape=(N,) (or the > [:,newaxis] version which produces shape=(N,1). > > But what is the point of the ones(3)? I think

Re: [Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Andrew Jaffe
On 08/02/2011 16:44, Ben Gamari wrote: > I have an array of (say, row) vectors, > >v = [ [ a1, a2, a3 ], > [ b1, b2, b3 ], > [ c1, c2, c3 ], > ... >] > > What is the optimal way to compute the norm of each vector, >norm(v)**2 = [ >[ a1**2 + a2**2 +

Re: [Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Robert Kern
On Tue, Feb 8, 2011 at 11:55, Ben Gamari wrote: > On Tue, 8 Feb 2011 10:46:34 -0600, Robert Kern wrote: >> (v*v).sum(axis=1)[:,np.newaxis] >> >> You can leave off the newaxis bit if you don't really need a column vector. >> > Fair enough, I unfortunately neglected to mention that I ultimately wan

Re: [Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Ben Gamari
On Tue, 8 Feb 2011 10:46:34 -0600, Robert Kern wrote: > (v*v).sum(axis=1)[:,np.newaxis] > > You can leave off the newaxis bit if you don't really need a column vector. > Fair enough, I unfortunately neglected to mention that I ultimately want to normalize these vectors, hence the *ones(3) in my

Re: [Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Robert Kern
On Tue, Feb 8, 2011 at 10:44, Ben Gamari wrote: > I have an array of (say, row) vectors, > >  v = [ [ a1, a2, a3 ], >        [ b1, b2, b3 ], >        [ c1, c2, c3 ], >        ... >      ] > > What is the optimal way to compute the norm of each vector, >  norm(v)**2 = [ >      [ a1**2 + a2**2 + a3*

[Numpy-discussion] Computing the norm of an array of vectors

2011-02-08 Thread Ben Gamari
I have an array of (say, row) vectors, v = [ [ a1, a2, a3 ], [ b1, b2, b3 ], [ c1, c2, c3 ], ... ] What is the optimal way to compute the norm of each vector, norm(v)**2 = [ [ a1**2 + a2**2 + a3**2 ], [ b1**2 + b2**2 + b3**2 ], ... ] It see