[Numpy-discussion] object arrays and ==

Keith Goodman kwgoodman@gmail....
Mon May 4 16:19:59 CDT 2009


On Mon, May 4, 2009 at 2:02 PM, Ryan May <rmay31@gmail.com> wrote:
> On Mon, May 4, 2009 at 3:55 PM, David Warde-Farley <dwf@cs.toronto.edu>
> wrote:
>>
>> Hi,
>>
>> Is there a simple way to compare each element of an object array to a
>> single object? objarray == None, for example, gives me a single
>> "False". I couldn't find any reference to it in the documentation, but
>> I'll admit, I wasn't quite sure where to look.
>
> I think it might depend on some factors:
>
> In [1]: a = np.array(['a','b'], dtype=np.object)
>
> In [2]: a=='a'
> Out[2]: array([ True, False], dtype=bool)
>
> In [3]: a==None
> Out[3]: False
>
> In [4]: a == []
> Out[4]: False
>
> In [5]: a == ''
> Out[5]: array([False, False], dtype=bool)
>
> In [6]: a == dict()
> Out[6]: array([False, False], dtype=bool)
>
> In [7]: numpy.__version__
> Out[7]: '1.4.0.dev6885'
>
> In [8]: a == 5
> Out[8]: array([False, False], dtype=bool)
>
> In [9]: a == 5.
> Out[9]: array([False, False], dtype=bool)
>
> But based on these results, I have no idea what the factors might be.  I
> know this works with datetime objects, but I'm really not sure why None and
> the empty list don't work.

Doing a little poking around, I found this:

>> a = np.array([True, False])
>> a == None
   False
>> np.equal(a, None)
   array([False, False], dtype=bool)


More information about the Numpy-discussion mailing list