【问题标题】:Suppress Scientific Notation in a list禁止列表中的科学记数法
【发布时间】:2020-09-22 03:25:47
【问题描述】:

我正在尝试生成泊松分布点,但 python 以科学计数法给我输出。我需要轻松地可视化数字并查看趋势,为此,我试图压制科学记数法。我已经尝试了许多在线可用的解决方案,但还没有运气。

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

输出:

[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]

【问题讨论】:

  • 你用过什么包。 ?
  • @Python_Learner 我的回答解决了你的问题吗?
  • @AliHasanAhmedKhan 是的,但有没有办法将其插入现有代码而无需添加更多代码行?我的意思是任何内置函数或类似的东西,因为我觉得如果我打算在我的原始代码中使用它,我希望它是健壮的。我很感谢你的帮助。谢谢!
  • @Python_Learner 现在检查我减少了一个循环

标签: python list jupyter-notebook decimal scientific-notation


【解决方案1】:

试试这个,更多压缩值试试 '.2f' 或者你想要的小数点。

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)

【讨论】:

    【解决方案2】:

    另一种方法是更改​​ numpy 打印选项,如下所示:

    np.set_printoptions(suppress=True)
    

    【讨论】:

      猜你喜欢
      • 2022-10-10
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 2022-01-19
      相关资源
      最近更新 更多