Re: [Numpy-discussion] str == int puzzlement

2010-08-01 Thread Friedrich Romstedt
2010/8/1 Matthew Brett matthew.br...@gmail.com: Maybe it would be better to raise a ValueError, which is not caught by the evaluation mechanism, to prevent such stuff. Sorry that this is not yet clear to me, but, is it true then that: The only situation where array.__eq__ sensibly falls back

Re: [Numpy-discussion] str == int puzzlement

2010-07-31 Thread Friedrich Romstedt
2010/7/29 Keith Goodman kwgood...@gmail.com: On Wed, Jul 28, 2010 at 6:42 PM, Matthew Brett matthew.br...@gmail.com wrote: Hi, Please forgive me if this is obvious, but this surprised me: In [15]: x = np.array(['a', 'b']) In [16]: x == 'a'  # this was what I expected Out[16]: array([

Re: [Numpy-discussion] str == int puzzlement

2010-07-31 Thread Matthew Brett
Hi, Yeah, it's just that numpy knows that it cannot compare pears with apples: a = numpy.asarray(['a', 'b']) a.__eq__(1) NotImplemented Thank you - that's very helpful and clear. Maybe it would be better to raise a ValueError, which is not caught by the evaluation mechanism, to prevent

Re: [Numpy-discussion] str == int puzzlement

2010-07-29 Thread Matthew Brett
Hi, On Wed, Jul 28, 2010 at 6:49 PM, John Salvatier jsalv...@u.washington.edu wrote: I think this is just Python behavior; comparing python ints and strs also gives False: In [45]: 8 == 'L' Out[45]: False Just to be clear, from: a = np.array(['a','b']) a == 1 I was expecting: array([

Re: [Numpy-discussion] str == int puzzlement

2010-07-29 Thread Keith Goodman
On Wed, Jul 28, 2010 at 6:42 PM, Matthew Brett matthew.br...@gmail.com wrote: Hi, Please forgive me if this is obvious, but this surprised me: In [15]: x = np.array(['a', 'b']) In [16]: x == 'a'  # this was what I expected Out[16]: array([ True, False], dtype=bool) In [17]: x == 1 # this

Re: [Numpy-discussion] str == int puzzlement

2010-07-28 Thread John Salvatier
I think this is just Python behavior; comparing python ints and strs also gives False: In [45]: 8 == 'L' Out[45]: False On Wed, Jul 28, 2010 at 6:42 PM, Matthew Brett matthew.br...@gmail.comwrote: Hi, Please forgive me if this is obvious, but this surprised me: In [15]: x = np.array(['a',

Re: [Numpy-discussion] str == int puzzlement

2010-07-28 Thread Sturla Molden
In [15]: x = np.array(['a', 'b']) In [16]: x == 'a' # this was what I expected Out[16]: array([ True, False], dtype=bool) In [17]: x == 1 # this was strange to me Out[17]: False Is it easy to explain why this is? I'll call this a bug in NumPy's broadcasting. x == 1 should have

Re: [Numpy-discussion] str == int puzzlement

2010-07-28 Thread Sturla Molden
I'll call this a bug in NumPy's broadcasting. x == 1 should have returned: This is probably related: In [22]: a = np.array(['a','b']) In [23]: a + 'c' --- TypeError Traceback (most recent

Re: [Numpy-discussion] str == int puzzlement

2010-07-28 Thread Sturla Molden
I'll call this a bug in NumPy's broadcasting. x == 1 should have returned: This is probably related: In [22]: a = np.array(['a','b']) In [23]: a + 'c' --- TypeError Traceback (most