【发布时间】:2019-08-01 10:24:40
【问题描述】:
谁能解释一下这里发生了什么?
为什么 0.3 和 0.7 的值有更多的小数点。 我只想要 1 个小数点值。
threshold_range = np.arange(0.1,1,0.1)
threshold_range.tolist()
[Output]: [0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7000000000000001, 0.8, 0.9]
【问题讨论】:
-
这是正确的行为。发生这种情况是因为 python 和大多数编程语言一样,由于浮点限制,不能完全表示一些小数。另见stackoverflow.com/questions/21895756/…
-
这很奇怪,打印出来对我来说很好。
-
@tnknepp 感谢您的评论。这就是我很好奇的部分。
标签: python python-3.x numpy data-science