I'm reading out a text file with some float numbers using np.loadtxt
. This is what my numpy array looks like:
x = np.loadtxt(t2)
print(x)
array([[ 1.00000000e+00, 6.61560000e-13],
[ 2.00000000e+00, 3.05350000e-13],
[ 3.00000000e+00, 6.22240000e-13],
[ 4.00000000e+00, 3.08850000e-13],
[ 5.00000000e+00, 1.11170000e-10],
[ 6.00000000e+00, 3.82440000e-11],
[ 7.00000000e+00, 5.39160000e-11],
[ 8.00000000e+00, 1.75910000e-11],
[ 9.00000000e+00, 2.27330000e-10]])
I separate out the first column from the second by doing this:
idx, coeffs = zip(*x)
Now, I want to create a mapping of id : coeff, something like this:
mapping = dict(zip(map(int, idx), coeffs))
print(mapping)
{1: 6.6155999999999996e-13,
2: 3.0535000000000001e-13,
3: 6.2223999999999998e-13,
4: 3.0884999999999999e-13,
5: 1.1117e-10,
6: 3.8243999999999997e-11,
7: 5.3915999999999998e-11,
8: 1.7591e-11,
9: 2.2733e-10}
As you can see, precision errors have been introduced. For example, 6.61560000e-13
became 6.6155999999999996e-13
.
This is what I would like, preferrably:
{1: 6.61560000e-13,
2: 3.05350000e-13,
3: 6.22240000e-13,
4: 3.08850000e-13,
...
}
How can I do this? I am working on IPython3, if that helps.