Python numpy scientific notation limit decimals
<p>I'm trying to reduce the number of decimals that I'm getting after some calculations. The <code>print()</code> where my problem arises looks like this:</p>

<pre><code>print("Mean resistivity: {res} Ohm m".format(res=np.mean(resistivity)))
</code></pre>

<p>And it outputs this:</p>

<pre><code>Mean resistivity: 1.6628449915450776e-08 Ohm m
</code></pre>

<p>Now I want to reduce the number of decimal places that are printed to 3. I tried doing it with string formatting, like this:</p>

<pre><code>print("Mean resistivity: {res:.3f} Ohm m".format(res=np.mean(resistivity)))
</code></pre>

<p>However, this code prints:</p>

<pre><code>Mean resistivity: 0.000 Ohm m
</code></pre>

<p>What I actually want is this:</p>

<pre><code>Mean resistivity: 1.663e-8 Ohm m
</code></pre>

<p>How can I format <code>res</code> to only be displayed as scientific notation but with only 3 decimal places?</p>

<p>It's python3? If so this should work: <code>{res:.3E}</code></p>

<p>@edit
It should work also with python2 - <a href="https://docs.python.org/2.7/library/string.html#formatspec" rel="nofollow">spec</a></p>

python numpy string-formatting scientific-notation