我正在使用numpy和numpy.array2string来探测微小变化和数值稳定性的影响。我对以下练习感到困惑:
<Get vector data through prior code>
print(data.shape)
print(data.dtype)
variance = np.var(data)
print(variance.dtype)
print(variance)
print(np.array2string(variance, suppress_small=True,formatter={'float': '{: 8.55f}'.format}))
哪个作为输出:
torch.Size([1, 64]) # shape of the data
torch.float32 # dtype of the data
float32 # dtype of the variance result
37166410.0
37166408.0000000000000000000000000000000000000000000000000000000
这让我感到cross目结舌:array2string不仅仅是用(明显荒谬的)数字重新格式化值,它似乎正在改变值本身,而超出了舍入错误应该很重要的程度。 (它不是似乎成为格式化程序,因为我可以删除它并仍然看到更改的值。)
float32可以轻松地直接表示这些整数值之一。
我在这里不明白什么?请重申我对客观现实的信念。
更新:没有float32不能完全代表37166410.0,我需要戴老花镜。