comparison between arrays of strings and numerical types
Hi, I find this a bit odd: In [18]: np.array(['a','b','c','d']) > 'a' Out[18]: array([False, True, True, True], dtype=bool) In [19]: np.array(['a','b','c','d']) > 4 Out[19]: True In [20]: np.array(['a','b','c','d']) > 4.5 Out[20]: True Is that right? I was expecting an element-wise comparison, but it returns a single truth value. Cheers, Ernest
2010/8/31 Ernest Adrogué <eadrogue@gmx.net>:
Hi,
I find this a bit odd:
In [18]: np.array(['a','b','c','d']) > 'a' Out[18]: array([False, True, True, True], dtype=bool)
In [19]: np.array(['a','b','c','d']) > 4 Out[19]: True
In [20]: np.array(['a','b','c','d']) > 4.5 Out[20]: True
Is that right? I was expecting an element-wise comparison, but it returns a single truth value.
Here's a recent discussion of the issue: http://www.mail-archive.com/numpy-discussion@scipy.org/msg27051.html
31/08/10 @ 09:44 (-0700), thus spake Keith Goodman:
2010/8/31 Ernest Adrogué <eadrogue@gmx.net>:
Hi,
I find this a bit odd:
In [18]: np.array(['a','b','c','d']) > 'a' Out[18]: array([False, True, True, True], dtype=bool)
In [19]: np.array(['a','b','c','d']) > 4 Out[19]: True
In [20]: np.array(['a','b','c','d']) > 4.5 Out[20]: True
Is that right? I was expecting an element-wise comparison, but it returns a single truth value.
Here's a recent discussion of the issue: http://www.mail-archive.com/numpy-discussion@scipy.org/msg27051.html
Ah, I suppose I wasn't paying attention :) There appears to be an open ticket as well: http://projects.scipy.org/numpy/ticket/725 Regards, Ernest
participants (2)
-
Ernest Adrogué
-
Keith Goodman