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.
___
NumPy-Discussion mailing list
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.
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 this, but will
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
comparison fails?
I'm
On Wed, Oct 27, 2010 at 9:37 AM, Johann Cohen-Tanugi
co...@lpta.in2p3.fr 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, compare 2
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.
any()
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.
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
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 create a
On Wed, Oct 27, 2010 at 7:34 AM, Neal Becker ndbeck...@gmail.com 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
10 matches
Mail list logo