Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print scientific notation number into same scale

Tags:

python

numpy

I want to print scientific notation number with same scale in python. For example I have different numbers (1e-6, 3e-7, 5e-7, 4e-8)so now I want to print all these numbers with e-6 notation (1e-6, 0.3e-6, 0.5e-6, 0.04e-6). So how can I print it?

Thanks

like image 487
physics_for_all Avatar asked Sep 05 '25 03:09

physics_for_all


2 Answers

Mathematically, tacking on e-6 is the same as multiplying by 1e-6, right?

So, you've got a number x, and you want to know what y to use such that y * 1e-6 == x.

So, just multiply by 1e6, render that in non-exponential format, then tack on e-6 as a string:

def e6(x):
  return '%fe-6' % (1e6 * x,)
like image 116
abarnert Avatar answered Sep 07 '25 19:09

abarnert


using log10:

In [64]: lis= (1e-6, 3e-7, 5e-7, 4e-8)

In [65]: import math

In [66]: for x in lis:
    exp=math.floor(math.log10(x))
    num=x/10**exp              
    print "{0}e-6".format(num*10**(exp+6))
   ....:     
   ....:     
1.0e-6
0.3e-6
0.5e-6
0.04e-6
like image 33
Ashwini Chaudhary Avatar answered Sep 07 '25 19:09

Ashwini Chaudhary