computing averages and ensemble averages