[Numpy-discussion] Fast clip for native types, 2d version
david at ar.media.kyoto-u.ac.jp
Sun Jan 14 22:16:34 CST 2007
Robert Kern wrote:
> David Cournapeau wrote:
>> Robert Kern wrote:
>>> 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,
>> Could you tell me where this was discussed, I think I missed it.
Ok, thank you.
>> Thanks for the precision. Is this the expected behaviour for endianness,
>> too ?
> What endianness behaviour?
This (assuming your machine is little endian):
In : import numpy
In : a = numpy.random.randn(3, 2)
In : b = a.astype(a.dtype.newbyteorder('>'))
In : a.clip(0., 1.).dtype.isnative
In : b.clip(0., 1.).dtype.isnative
In : b.clip(numpy.zeros(b.shape), 1.).dtype.isnative
If input is byteswapped, the output is also byteswapped for scalar
min/max, but native if a native array is given as a min/max argument.
More information about the Numpy-discussion