元组到numpy,数据准确性
当我将元组转换为Numpy时,数据准确性存在问题。我的代码就是这样:
import numpy as np
a=(0.547693688614422, -0.7854270889025808, 0.6267478456110592)
print(a)
print(type(a))
tmp=np.array(a)
print(tmp)
结果就是这样:
(0.547693688614422, -0.7854270889025808, 0.6267478456110592)
<class 'tuple'>
[ 0.54769369 -0.78542709 0.62674785]
为什么?
When I convert a tuple to numpy, there is a problem with data accuracy. My code is like this:
import numpy as np
a=(0.547693688614422, -0.7854270889025808, 0.6267478456110592)
print(a)
print(type(a))
tmp=np.array(a)
print(tmp)
The result is like this:
(0.547693688614422, -0.7854270889025808, 0.6267478456110592)
<class 'tuple'>
[ 0.54769369 -0.78542709 0.62674785]
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎差异应该只是显示数字的方式,而不是它们的表示 /存储方式。
您可以检查
dtype
以验证它仍然是float64您可以调整
np.set_printoptions
以查看它们的值以不同的方式显示This seeming discrepancy should just be how the numbers are being displayed, not how they are being represented / stored.
You can check the
dtype
to verify it is still float64You can adjust
np.set_printoptions
to see them values displayed differently我认为您仅在 display 中看到截断,但是内部值仍然保留原始精度。这是我发现的:
因此,没有理由更改任何设置 - 使用这些阵列执行的数学仍将完全准确。
I think you're only seeing a truncation in display only, but the internal value still retains the original accuracy. Here's what I found:
So there's no reason to change any settings - math performed with these arrays will still be at full accuracy.
一种方法是设置以下方式:
One way is to set this: