Sum of deviations from mean - Numpy code issue

sum of deviations from mean not coming out to be 0 with code-

np.sum(arr - np.mean(arr))
It gives answer as -1.7008616737257398e-12

Hi @priyanka,
Is it a 1D array?
If not can you please make sure that you’re summing up over correct axis?
If yes, can you share the values inside this array?

It a ID array only.

arr = np.random.rand(100000)
np.sum(arr - np.mean(arr))
-6.617817405185633e-12

ok so in next video sir explains that sum of mean might not come out of 0 due to truncation issues.

@priyanka
e-12 means 10^-12
Above number is basically: 0.000000000006167.. which can be safely approximated to 0 (a common practise in floating point arithmetic).

1 Like