python - Numpy average function rounding off error -


i find weird. can tell me whats going on here?

>>>a = [1,0,1] >>>np.mean(a)    0.66666666666666663 >>>2.0/3    0.6666666666666666 

what's 3 in end of output of np.mean(a)? why isn't 6 line below or 7(when rounding off)?

this case of different string representation of 2 different types:

in [17]: = [1, 0, 1]  in [18]: mean(a) out[18]: 0.66666666666666663  in [19]: type(mean(a)) out[19]: numpy.float64  in [20]: 2.0 / 3 out[20]: 0.6666666666666666  in [21]: type(2.0 / 3) out[21]: float  in [22]: mean(a).item() out[22]: 0.6666666666666666 

they compare equal:

in [24]: mean(a) == 2.0 / 3 out[24]: true  in [25]: mean(a).item() == 2.0 / 3 out[25]: true 

now might time read numpy scalars , numpy dtypes.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -