[Numpy-discussion] numpy.where behavior

2006-11-13 Thread vallis . 35530053
Using numpy 1.0, why does a = numpy.array([0.0,1.0,2.0],'d') numpy.where(a == 0.0,1,1/a) give the correct result, but with the warning Warning: divide by zero encountered in divide? ? I thought that the point of where was that the second expression is never used for the elements where

Re: [Numpy-discussion] numpy.where behavior

2006-11-13 Thread Robert Kern
[EMAIL PROTECTED] wrote: ? I thought that the point of where was that the second expression is never used for the elements where the condition evaluates true. It is not used, but the expression still gets evaluated. There's really no way around that. If this is the desired behavior, is

Re: [Numpy-discussion] numpy.where behavior

2006-11-13 Thread Tim Hochberg
[EMAIL PROTECTED] wrote: Using numpy 1.0, why does a = numpy.array([0.0,1.0,2.0],'d') numpy.where(a == 0.0,1,1/a) give the correct result, but with the warning Warning: divide by zero encountered in divide? ? I thought that the point of where was that

Re: [Numpy-discussion] numpy.where behavior

2006-11-13 Thread Paul Dubois
Unfortunately, where does not have the behavior of not evaluating the second argument where the first one is true. That would be nice (if the speed were ok) but it isn't possible unless where is built into the language, since where doesn't even get called until the arguments have all been

Re: [Numpy-discussion] numpy.where behavior

2006-11-13 Thread Robert Kern
Tim Hochberg wrote: Another little tidbit: this is not as general as where, and could probably be considered a little too clever to be clear, but: b = 1 / (a + (a==0.0)) is faster than using where in this particular case and sidesteps the divide by zero issue altogether. A less