[Numpy-discussion] object arrays and ==

Ryan May rmay31@gmail....
Mon May 4 16:02:52 CDT 2009

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.


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090504/970e2aa5/attachment.html 

More information about the Numpy-discussion mailing list