On Sat, May 15, 2010 at 11:03 PM, Gabriel Mihalache <[email protected]>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
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
