2

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
  • 3
    that's a display diffeeence Commented Aug 12, 2020 at 17:11

1 Answer 1

1

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] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.