NumPy calculate square of norm 2 of vector
I don't know if the performance is any good, but (a**2).sum() calculates the right value and has the non-repeated argument you want. You can replace a with some complicated expression without binding it to a variable, just remember to use parentheses as necessary, since ** binds more tightly than most other operators: ((a-b)**2).sum()
I have vector a.
I want to calculate np.inner(a, a)
But I wonder whether there is prettier way to calc it.
[The disadvantage of this way, that if I want to calculate it for a-b or a bit more complex expression, I have to do that with one more line. c = a - b and np.inner(c, c) instead of somewhat(a - b)]