[Numpy-discussion] Optimized sum of squares

Gary Ruben gruben@bigpond.net...
Sun Oct 18 05:06:15 CDT 2009

Hi Gaël,

If you've got a 1D array/vector called "a", I think the normal idiom is


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.

Gary R.

Gael Varoquaux wrote:
> On Sat, Oct 17, 2009 at 07:27:55PM -0400, josef.pktd@gmail.com wrote:
>>>>> Why aren't you using logaddexp ufunc from numpy?
>>>> Maybe because it is difficult to find, it doesn't have its own docs entry.
> Speaking of which...
> I thought that there was a readily-written, optimized function (or ufunc)
> in numpy or scipy that calculated the sum of squares for an array
> (possibly along an axis). However, I cannot find it.
> Is there something similar? If not, it is not the end of the world, the
> operation is trivial to write.
> Cheers,
> Gaël

More information about the NumPy-Discussion mailing list