python - Numpy - Difference between two floats vs float type's precision -


i looking @ numpy.finfo , did following:

in [14]: np.finfo(np.float16).resolution out[14]: 0.0010004 in [16]: np.array([0., 0.0001], dtype=np.float16) out[16]: array([ 0.        ,  0.00010002], dtype=float16) 

it seems vector able store 2 numbers such difference 10 times smaller type's resolution. missing something?

floating point numbers have fixed amount of resolution after initial digit. number telling is, when first digit @ 1.0 position, resolution of number. can see trying add smaller amounts 1.0:

in [8]: np.float16(1) + np.float16(0.001) out[8]: 1.001  in [9]: np.float16(1) + np.float16(0.0001) out[9]: 1.0 

this related nextafter function, gives next representable number after given one. taking difference gives approximately resolution:

in [10]: np.nextafter(np.float16(1), np.float16(np.inf)) - np.float16(1) out[10]: 0.00097656 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -