I have a Python list like so:
import numpy
thresholds = numpy.linspace(0.7, 0.9, 21)
print(thresholds)
[0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9]
When I try to create a dict
from this list by doing dict.fromkeys()
, the result isn't as expected:
thresholds = dict.fromkeys(numpy.linspace(0.7, 0.9, 21))
print(thresholds)
{0.69999999999999996: None, 0.70999999999999996: None, 0.84999999999999998: None, 0.83000000000000007: None, 0.81000000000000005: None, 0.79000000000000004: None, 0.77000000000000002: None, 0.78000000000000003: None, 0.72999999999999998: None, 0.83999999999999997: None, 0.71999999999999997: None, 0.89000000000000001: None, 0.87: None, 0.80000000000000004: None, 0.76000000000000001: None, 0.90000000000000002: None, 0.73999999999999999: None, 0.88: None, 0.85999999999999999: None, 0.82000000000000006: None, 0.75: None}
I was expecting a dict
like this:
{0.7: None, 0.71: None, 0.85: None, 0.83: None, 0.81: None, 0.79: None, 0.77: None, 0.78: None, 0.73: None, 0.84: None, 0.72: None, 0.90: None, 0.87: None, 0.80: None, 0.76: None, 0.90: None, 0.74: None, 0.88: None, 0.86: None, 0.82: None, 0.75: None}
Why do I not get rounded values in the final dict
and how do I go about correcting this?