Calculate the energy of an array.