Python decimal decimal places numpy

I am trying to reduce the number of decimal places that I get after some calculations. print() , where my problem occurs, is as follows:

 print("Mean resistivity: {res} Ohm m".format(res=np.mean(resistivity))) 

And he deduces this:

 Mean resistivity: 1.6628449915450776e-08 Ohm m 

Now I want to reduce the number of decimal places that were printed to 3. I tried doing this with string formatting, for example:

 print("Mean resistivity: {res:.3f} Ohm m".format(res=np.mean(resistivity))) 

However, this code prints:

 Mean resistivity: 0.000 Ohm m 

I really want:

 Mean resistivity: 1.663e-8 Ohm m 

How can I format res only for display as scientific notation, but with only three decimal places?

+6
source share
1 answer

Is it python3? If so, then this should work: {res:.3E}

@edit It should work also with python2 - spec

+6
source

All Articles