0

Can someone explain to my why, according to many average calculators, the average of this array is some very small negative number instead of zero?

[-5.4, -4.4, -2.4, -1.4, 13.6]

for example, numpy.average and numpy.mean return this value:

-3.5527136788e-16
ajohanns
  • 1
  • 2

1 Answers1

0

Because float numerics is not perfect. And simply this does not sum to 0, but to something around 1e-14 in this system. You can find even more funny things - change order of your numbers and then calculate sum/mean and you will find that result depends on ordering too. The short story is that you cannot express 0.4 nor 0.6 in base 2, which is used in computers.

lejlot
  • 64,777
  • 8
  • 131
  • 164