我正在用这个简单的代码创建一个字典:
pixel_histogram = {}
min_value = -0.2
max_value = 0.2
interval_size = (math.fabs(min_value) + math.fabs(max_value))/bins
for i in range(bins):
key = min_value+(i*interval_size)
print key
pixel_histogram[key] = 0
print pixel_histogram
但我有点惊讶,因为我的打印得到了这些值:
#Printing keys
-0.2
-0.16
-0.12
-0.08
-0.04
0.0
0.04
0.08
0.12
0.16
#Printing the dictionary
{0.0: 0,
-0.08000000000000002: 0,
0.15999999999999998: 0,
-0.16: 0,
0.12: 0,
-0.12000000000000001: 0,
0.08000000000000002: 0,
-0.04000000000000001: 0,
-0.2: 0,
0.03999999999999998: 0}
我没有弄清楚为什么值不同以及如何解决这个问题。任何帮助,将不胜感激。谢谢。