2009/10/20  <josef.p...@gmail.com>:
> On Sun, Oct 18, 2009 at 6:06 AM, Gary Ruben <gru...@bigpond.net.au> wrote:
>> Hi Gaƫl,
>>
>> If you've got a 1D array/vector called "a", I think the normal idiom is
>>
>> np.dot(a,a)
>>
>> For the more general case, I think
>> np.tensordot(a, a, axes=something_else)
>> should do it, where you should be able to figure out something_else for
>> your particular case.
>
> Is it really possible to get the same as np.sum(a*a, axis)  with
> tensordot  if a.ndim=2 ?
> Any way I try the "something_else", I get extra terms as in np.dot(a.T, a)

It seems like this would be a good place to apply numpy's
higher-dimensional ufuncs: what you want seems to just be the vector
inner product, broadcast over all other dimensions. In fact I believe
this is implemented in numpy as a demo: numpy.umath_tests.inner1d
should do the job.


Anne
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to