[Numpy-discussion] Fast clip for native types, 2d version
robert.kern at gmail.com
Sun Jan 14 05:54:46 EST 2007
David Cournapeau wrote:
> 2: the old implementation does not upcast the input array. If the
> input is int32, and min/max are float32, the function fails; if input is
> float32, and min/max float64, the output is still float32. Again, this
> seems against the expected numpy behaviour ?
The latter is expected. As discussed previously here, the types of scalars are
ignored. You do get an upcast when either min or max is a float64 array.
In : import numpy
In : a = numpy.linspace(0, 10, 101)
In : a = numpy.linspace(0, 10, 101).astype(numpy.float32)
In : a.clip(numpy.float64(5), numpy.float64(6)).dtype
In : a.clip(numpy.ones(101, dtype=numpy.float64), numpy.float64(6)).dtype
The int32/float32 failure is odd, though.
"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