how to use an atom vector in a function

Dear all
I want to do some operation like this:
suppose we have a group with N atoms. i want to sum vx^2 of the atoms in the group i.e.:

vx(1)^2 +vx(2)^2 +…+vx(n)^2

how can i do this? (i tried to use "compute property/atom command " and “variable command” and “compute reduce command” to do that but the operation was not successful)

Make a variable that is vx*vx, then sum it with
compute reduce which will give you a scalar,
which you can output with thermo output.