numpy.where behavior

Robert Kern robert.kern at gmail.com
Mon Nov 13 23:16:55 EST 2006


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 clever approach that does much the same thing:

  b = 1.0 / where(a==0, 1.0, a)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list