I have this array
A = array([[-0.49740509, -0.48618909, -0.49145315],
[-0.48959259, -0.48618909, -0.49145315],
[-0.49740509, -0.47837659, -0.49145315],
...,
[ 0.03079315, -0.01194593, -0.06872366],
[ 0.03054901, -0.01170179, -0.06872366],
[ 0.03079315, -0.01170179, -0.06872366]])
which is a collection of 3D vector. I was wondering if I could use a vectorial operation to get an array with the norm of each of my vector.
I tried with norm(A)
but it didn't work.
Doing it manually might be fastest (although there's always some neat trick someone posts I didn't think of):
This assumes everything's real. Could multiply by the conjugate instead if that's not true.
Update: Eric's suggestion of using
math.sqrt
won't work -- it doesn't handle numpy arrays -- but the idea of using sqrt instead of**0.5
is a good one, so let's test it.I tried it a few times, and this was the largest difference I saw.