You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mathematically, the second result should have been the same as the first, repeated twice. But instead I get a slightly different numerical result (1.0000001 instead of 1.0). This inconsistency actually matters for my program.
Any insight to why this is happening, and possible workarounds?
I use NumPy 1.14.1.
Python version: 2.7.12+ (default, Aug 4 2016, 20:04:34) [GCC 6.1.1 20160724]
OS: Debian GNU/Linux 9
Thank you.
The text was updated successfully, but these errors were encountered:
You cannot numerically expect the result to be exactly 1.0, the other value is numerically just as correct (or correct enough).
Numpy and especially the linear algebra routines that numpy uses, for example optimize memory access for speed. Such thing reorder the actual numerical operations taking place, which can cause different round off errors to occur.
Such round of errors will not be stable on different platforms or even hardware.
You should not rely on floats to be exactly equal normally, there is a reason functions to compare whether they are almost equal exist.
Also, unless you are clear about such round of issues and you know that it works fine for you, do not use float32! There is a readon float64 is the default. So the normal workaround: Use float64, and the numerical error will be a few magnitudes smaller, or some arbitrary precision types.
You might get what you want by replacing or reordering the dot product, but there is no guarantee it will work always.
I run the following code:
And get the following output:
Mathematically, the second result should have been the same as the first, repeated twice. But instead I get a slightly different numerical result (1.0000001 instead of 1.0). This inconsistency actually matters for my program.
Any insight to why this is happening, and possible workarounds?
I use NumPy 1.14.1.
Python version: 2.7.12+ (default, Aug 4 2016, 20:04:34) [GCC 6.1.1 20160724]
OS: Debian GNU/Linux 9
Thank you.
The text was updated successfully, but these errors were encountered: