Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Nathaniel Smith
On Wed, Oct 27, 2010 at 7:34 AM, Neal Becker wrote: > I propose adding is_equal(a,b) function which does true short-ciruciting You could use np.allclose, I guess. (It isn't short-circuiting right now, but you could fix that.) -- Nathaniel ___ NumPy-Dis

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Neal Becker
Pauli Virtanen wrote: > Wed, 27 Oct 2010 09:44:59 -0400, Skipper Seabold wrote: > [clip] >> In [35]: timeit np.any(a!=b) > [clip] >> It seems to at least take less time when the difference is at the >> "beginning," though I'm sure there could be exceptions. > > It performs all the comparisons to

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Alan G Isaac
On 10/27/2010 9:56 AM, Zachary Pincus wrote: > the structure of the python language prevents > meaningful short-circuiting in the case of > np.any(a!=b) Maybe: any((ai != bi) for ai,bi in izip(a.flat,b.flat)) ? fwiw, Alan Isaac ___ NumPy-Discussion mai

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Zachary Pincus
This is silly: the structure of the python language prevents meaningful short-circuiting in the case of np.any(a!=b) While it's true that np.any itself may short-circuit, the 'a!=b' statement itself will be evaluated in its entirety before the result (a boolean array) is passed to np.any. Th

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Pauli Virtanen
Wed, 27 Oct 2010 09:44:59 -0400, Skipper Seabold wrote: [clip] > In [35]: timeit np.any(a!=b) [clip] > It seems to at least take less time when the difference is at the > "beginning," though I'm sure there could be exceptions. It performs all the comparisons to create a temporary boolean array. an

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Skipper Seabold
On Wed, Oct 27, 2010 at 9:37 AM, Johann Cohen-Tanugi wrote: > > > On 10/27/2010 03:31 PM, Neal Becker wrote: >> Johann Cohen-Tanugi wrote: >> >> >>> how about np.any(a!=b)  ?? >>> >>> On 10/27/2010 12:25 PM, Neal Becker wrote: >>> Is there a way to get a short circuit != ? That is,

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Johann Cohen-Tanugi
On 10/27/2010 03:31 PM, Neal Becker wrote: > Johann Cohen-Tanugi wrote: > > >> how about np.any(a!=b) ?? >> >> On 10/27/2010 12:25 PM, Neal Becker wrote: >> >>> Is there a way to get a short circuit != ? >>> >>> That is, compare 2 arrays but stop as soon as the first element >>> compar

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Neal Becker
Johann Cohen-Tanugi wrote: > how about np.any(a!=b) ?? > > On 10/27/2010 12:25 PM, Neal Becker wrote: >> Is there a way to get a short circuit != ? >> >> That is, compare 2 arrays but stop as soon as the first element >> comparison fails? >> >> I'm assuming that np.all (a != b) will _not_ do thi

Re: [Numpy-discussion] short circuit != ?

2010-10-27 Thread Johann Cohen-Tanugi
how about np.any(a!=b) ?? On 10/27/2010 12:25 PM, Neal Becker wrote: > Is there a way to get a short circuit != ? > > That is, compare 2 arrays but stop as soon as the first element comparison > fails? > > I'm assuming that np.all (a != b) will _not_ do this, but will first compare > all elements