简体   繁体   中英

Suppress Scientific Notation in a list

I am trying to generate Poisson distributed points but python is giving me outputs in scientific notation. I need to easily visualize numbers and see the trend and for that, I am trying to suppress the scientific notation. I have tried many solutions available online but no luck yet.

x = []
for i in range(0,50):
    x.append(poisson.pmf(i, 10))
print(x)
plt.plot(x)

Output:

[4.5399929762484854e-05, 0.0004539992976248486, 0.0022699964881242435, 
 0.007566654960414144, 0.01891663740103538, 0.03783327480207079, 
 0.06305545800345125, 0.090079225719216, 0.11259903214902009, 
 0.12511003572113372, 0.12511003572113372, 0.11373639611012128, 0.09478033009176803, 0.07290794622443707, 0.05207710444602615, 
 0.034718069630684245, 0.021698793519177594, 0.012763996187751505, 
 0.007091108993195334, 0.003732162627997529, 0.0018660813139987742, 
 0.0008886101495232241, 0.0004039137043287357, 0.00017561465405597286, 
 7.317277252332212e-05, 2.9269109009328823e-05, 1.125734961897266e-05, 
 4.169388747767671e-06, 1.4890674099170028e-06, 5.134715206610449e-07, 
 1.7115717355368203e-07, 5.521199146892901e-08, 1.725374733404048e-08, 
 5.228408283042485e-09, 1.537767142071341e-09, 4.393620405918148e-10, 
 1.2204501127550308e-10, 3.2985138182568977e-11, 8.680299521728504e-12, 
 2.225717826084264e-12, 5.56429456521064e-13, 1.3571450159050293e-13, 
 3.23129765691677e-14, 7.514645713759808e-15, 1.7078740258545124e-15, 
 3.795275613009891e-16, 8.250599158717587e-17, 1.755446629514306e-17, 
 3.6571804781549065e-18, 7.463633628887677e-19]

Try this, for more compressed values try '.2f' or what ever decimal points you want.

x = []
for i in range(0,50):
    x.append(s.poisson.pmf(i, 10))
    x[i] = format(x[i], 'f')
print(x)
plt.plot(x)

这是输出

An alternative is to change the numpy print options as follows:

np.set_printoptions(suppress=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM