Wrong Eigenvalue (Approximation?)
Hello, all! I'm new to Numpy and Python so please tolerate by ignorance on this but I'm having problems with some weird behavior. Consider the session:
import numpy as np import numpy.linalg as la x = np.array([[0.3, 0.2, 0.5], [0.2, 0.1, 0.7], [0.9, 0.05, 0.05]]).transpose() esystem = la.eig(x) esystem[0] array([ 1. , 0.3 , 0.25]) esystem[0][0] 1.0000000000000004
The eigenvalue should be 1 exactly. In fact, later on I want to be able to do np.where(x == 1) which fails. The way I set up the matrix, I know for sure that there must be one eigenvalue exactly equal to 1. Any help is greatly appreciated! This is all on Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Regards, Gabriel
On Sat, May 15, 2010 at 11:03 PM, Gabriel Mihalache <mihalache@gmail.com>wrote:
Hello, all! I'm new to Numpy and Python so please tolerate by ignorance on this but I'm having problems with some weird behavior. Consider the session:
import numpy as np import numpy.linalg as la x = np.array([[0.3, 0.2, 0.5], [0.2, 0.1, 0.7], [0.9, 0.05, 0.05]]).transpose() esystem = la.eig(x) esystem[0] array([ 1. , 0.3 , 0.25]) esystem[0][0] 1.0000000000000004
This seems correct to me. Floating point calculations in any language is not exact because of issues with how decimal numbers are stored in binary. Therefore...
The eigenvalue should be 1 exactly. In fact, later on I want to be able to do
np.where(x == 1)
which fails.
is entirely expected. Trying to perform equality comparisons between floating point numbers is almost always doomed to failure, no matter which language you choose. There are plenty of resources on the internet about this, and it is very common to interpret as a bug by newcomers to scientific computing. I hope this helps. Ben Root
On 5/16/2010 12:03 AM, Gabriel Mihalache wrote:
The eigenvalue should be 1 exactly.
http://floatingpointgui.de/ hth, Alan Isaac
Floating point numbers; one of my recent favorite subjects... See this hot Slashdot discussion subject: what every programmer should know about floatingpoint arithmetic On 5/16/10, Alan G Isaac <aisaac@american.edu> wrote:
On 5/16/2010 12:03 AM, Gabriel Mihalache wrote:
The eigenvalue should be 1 exactly.
hth, Alan Isaac
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
 Gökhan
On Sun, May 16, 2010 at 2:13 PM, Alan G Isaac <aisaac@american.edu> wrote:
On 5/16/2010 12:03 AM, Gabriel Mihalache wrote:
The eigenvalue should be 1 exactly.
Hi, just wondering why that site you just referred doesn't say who the author is !? It looks very nice (i.e. pleasing to the eye...)  Sebastian Haase
Sebastian Haase wrote:
On Sun, May 16, 2010 at 2:13 PM, Alan G Isaac <aisaac@american.edu> wrote:
On 5/16/2010 12:03 AM, Gabriel Mihalache wrote:
The eigenvalue should be 1 exactly. http://floatingpointgui.de/
Hi, just wondering why that site you just referred doesn't say who the author is !? It looks very nice (i.e. pleasing to the eye...)
Very nice indeed! Top right link "fork me at github" leads you to the author, Michael Borgwardt.
participants (6)

Alan G Isaac

Benjamin Root

Gabriel Mihalache

Gökhan Sever

Jon Wright

Sebastian Haase