【问题标题】:Stop auto rounding in numpy在numpy中停止自动舍入
【发布时间】:2022-01-17 22:15:02
【问题描述】:

我有这段代码,但结果中的值被转换为整数。我想要真正的价值。如何?感谢您的帮助。


import numpy as np

a=np.array([1,2,3,4])

f=np.array([0.00020,0.0001])

for i in range(2):
    a[i]=f[i]
print(a)
# [0 0 3 4]

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    a 是一个整数数组,你必须将它设置为一个浮点数组

    a=np.array([1,2,3,4], dtype=float)
    

    【讨论】:

      猜你喜欢
      • 2016-06-04
      • 2019-07-17
      • 2021-12-29
      • 2020-06-06
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      相关资源
      最近更新 更多