rounding - Reduce the decimal points in Python -


i have array array([0.79836512, 0.79700273, 0.82697546, 0.82016349, 0.79087192], dtype=float32)

and want keep first 2 decimal points without round. so, need array that,

array([0.79, 0.79, 0.82, 0.82, 0.79], dtype=float32).

is possible python?

thanks

the standard approach truncating 2 decimals truncate x * 100 , divide 100, works numpy arrays:

>>> np.trunc(a * 100) / 100 array([ 0.79000002,  0.79000002,  0.81999999,  0.81999999,  0.79000002], dtype=float32) 

don't put off trailing non-zero digits in output, artifact of floating-point imprecision:

>>> np.float32(.79) 0.79000002 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -