[Numpy-discussion] Unexpected warnings in where

Todd Miller jmiller at stsci.edu
Thu May 13 10:02:02 CDT 2004

On Thu, 2004-05-13 at 12:34, Álvaro Tejero Cantero wrote:
> > I think what you're seeing is this:
> > 
> > where(condition, expression1, expression2)
> > 
> > Even though condition is selecting parts of expression1 which are valid,
> > expression1 is still fully evaluated.
> Is this behaviour what is intended, or do you consider it a shortcoming
> of the implementation?. In theory avoiding unneeded evaluations of
> expression1 is very desirable...

This just falls out of Python function call semantics: parameters are
evaluated before a function is called.   It is a property of Python so I
think we're stuck with it.

Two things come to mind to get rid of the warnings:

1. Stuff the input arrays with values which avoid the warnings.
condition = logical_and(RV<0,discr>0)
discr[condition] = 1
VV[condition] = 1
newtimes = where(condition, (-RV-sqrt(discr))/VV, far_future)

2. Use the Error system to suppress the warnings:

Error.pushMode(dividebyzero="ignore", invalid="ignore")
newtimes = where(logical_and(RV<0,discr>0), (-RV-sqrt(discr))/VV,


More information about the Numpy-discussion mailing list