[SciPy-user] "in" vs. looped "=="
Alan G Isaac
Wed Mar 12 16:16:06 CDT 2008
On Wed, 12 Mar 2008, "R. Padraic Springuel" apparently wrote:
> I have some code that uses a "1. in x" statement early on,
> where x is a rank-1 ndarray with dtype=float. This
> statement returns False and the program continues
> accordingly. However, later on in the same code I loop
> over the elements of x and the statement "x[i] == 1" is
> evaluated and comes back as True for some elements of x.
> To my mind, that shouldn't be happening. Is there
> a difference in how "1. in x" (i.e. the __contains__
> method of ndarray) and "x[i] == 1." (i.e. the __eq__
> property of float) behave that I'm not aware of?
There is a difference, if I recall correctly, but it will
not cause this.
The difference is that ``in`` will first check an item for
``is`` and then check it for ``__eq__``.
But since this would not affect your results, the most
likely possibility seems that you are changing the array somehow.
A small example would help.
More information about the SciPy-user