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)]
Honestly there's probably not going to be anything faster than
np.innerornp.dot. If you find intermediate variables annoying, you could always create a lambda function:np.innerandnp.dotleverage BLAS routines, and will almost certainly be faster than standard elementwise multiplication followed by summation.np.linalg.norm(..., ord=2)usesnp.dotinternally, and gives very similar performance to usingnp.innerdirectly.