[Numpy-discussion] Re: Why floor and ceil change the type of the array?

Sasha ndarray at mac.com
Wed Feb 22 20:49:08 EST 2006


On 2/22/06, Robert Kern <robert.kern at gmail.com> wrote:
> Sasha wrote:
> > ... wouldn't it
> > be more natural if fllor and ceil return the argument unchanged (maybe
> > a copy) if it is already integer?
>
> Only if floor() and ceil() returned integer arrays when given floats as input. I
> presume there are good reasons for this, since it's the same behavior as the
> standard C functions.

C does not have ceil(int).  It has

       double ceil(double x);
       float ceilf(float x);
       long double ceill(long double x);

and neither of these functions change the type of the argument.

Numpy's "around" is a noop on integers (even for decimals<0, but
that's a different story.

I cannot really think of any reason for the current numpy behaviour
other than the consistency with transcendental functions.  Speaking of
which, can someone explain this:

>>> sin(array(1,'h')).dtype
dtype('<f4')
>>> sin(array(1,'i')).dtype
dtype('<f8')




More information about the NumPy-Discussion mailing list