Difference in precision in np.float64 and python float (64)

Viewed 101

Why does (or seems that) the python float has more precision than numpy.float64. Here I leave an example:

import numpy as np

ann = 72.595895691
detections = np.array([0, 71.91000009999999], dtype=np.float64)
group_det = [1]
dist1 = [ann - detections[det] for det in group_det]
dist = np.zeros(len(group_det), dtype=np.float64)
for idx, det in enumerate(group_det):
    dist[idx] = ann - detections[det]
print(f'dist1: {dist1}')
print(f'dist {dist}')

The output of this code is:

dist1: [0.6858955910000049]
dist [0.68589559]

My questions is why dist1 has more precision?

Note: The code seems like is doing things in a very complicated way, but I had to cut a little portion of my code with the same behaviour.

1 Answers

As mentioned by @hpaulj in comments, it is not calculation precision. It is printing. Add this line to your code to see the precision you would like while printing in numpy:

np.set_printoptions(precision=16)

output of your code after above line:

dist1: [0.6858955910000049]
dist [0.6858955910000049]
Related