[Numpy-discussion] numpy.where

Robert Kern robert.kern at gmail.com
Sat Jul 14 17:15:00 EDT 2007

Sebastian Haase wrote:
> Hi.
> Two things.
> 1) The doc-string of numpy.where() states that transpose(where(cond,
> x,y)) whould always return a 2d-array. How can this be true?? It also
> says (before) that if x,y are given where(cond,x,y) always returns an
> array of the same shape as cond ....

It is wrong. It actually meant


> 2) Could we have another optional argument "dtype" in numpy.where()?
> Otherwise I would have to always write code like this:
> a = N.where( arr>x, 1.0, 0.0)
> a = a.astype(N.float32)

a = N.where(arr > x, N.float32(1), N.float32(0))

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

More information about the NumPy-Discussion mailing list