Re: [Numpy-discussion] ceil returns real ?
On Wed, Jul 28, 2010 at 2:26 PM, Mark Bakker mark...@gmail.com wrote: Hello list, I don't understand why ceil and floor return real values, while the doc string says: The ceil of the scalar `x` is the smallest integer `i` Wouldn't an integer make more sense? Numpy version 1.3.0. Thanks, Hi Mark, I don't know the answer, but Python 2.x has similar behavior for the built-in round(): round(2.7) returns 3.0 (float!) I think I read that Python 3.2 will change this to round(2.7) returning 3 (int!) - Sebastian Haase ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
On 7/28/2010 8:26 AM, Mark Bakker wrote: I don't understand why ceil and floor return real values The same for ``round``. (Note that Python 3 rounds to int.) Furthermore, it would be nice if each took a ``dtype`` argument. Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote: I don't understand why ceil and floor return real values, while the doc string says: The ceil of the scalar `x` is the smallest integer `i` Wouldn't an integer make more sense? Which integer? Only arbitrary-size integers (Python longs) are able to span the whole floating-point range, but we don't necessarily want np.ceil(some_array) to start returning object arrays, because of efficiency reasons. Returning machine integers, on the other hand, can result to overflow. There, one should (i) raise exceptions on overflow, or, (ii) return bogus results for overflowed values. Numpy is here following the C tradition in defining the ceil and floor functions as float - float. This leaves overflow handling on casting to the user. Python can redefine its floor and ceil since arbitrary-size integers are first-class citizens in the Python world. This sits less well with Numpy: (i) Numpy tries to sit close to the hardware, and (ii) strictly speaking, arbitrary-size integers cannot be a Numpy scalar type since they by definition are not fixed-size in memory. -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote: I don't understand why ceil and floor return real values [snip] Wouldn't an integer make more sense? On 7/28/2010 9:39 AM, Pauli Virtanen wrote: Which integer? Only arbitrary-size integers (Python longs) are able to span the whole floating-point range, but we don't necessarily want np.ceil(some_array) to start returning object arrays, because of efficiency reasons. Makes sense. But couldn't a ``dtype`` argument still be useful? Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
On Wed, Jul 28, 2010 at 11:48, Alan G Isaac ais...@american.edu wrote: Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote: I don't understand why ceil and floor return real values [snip] Wouldn't an integer make more sense? On 7/28/2010 9:39 AM, Pauli Virtanen wrote: Which integer? Only arbitrary-size integers (Python longs) are able to span the whole floating-point range, but we don't necessarily want np.ceil(some_array) to start returning object arrays, because of efficiency reasons. Makes sense. But couldn't a ``dtype`` argument still be useful? Probably, but you would have to add it to all ufuncs. -- 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 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
Wed, 28 Jul 2010 14:26:36 +0200, Mark Bakker wrote: I don't understand why ceil and floor return real values [snip] Wouldn't an integer make more sense? On 7/28/2010 9:39 AM, Pauli Virtanen wrote: Which integer? Only arbitrary-size integers (Python longs) are able to span the whole floating-point range, but we don't necessarily want np.ceil(some_array) to start returning object arrays, because of efficiency reasons. Makes sense. But couldn't a ``dtype`` argument still be useful? np.ceil(some_array).astype(int) Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ceil returns real ?
Thu, 29 Jul 2010 01:16:14 +0200, Sturla Molden wrote: [clip] Makes sense. But couldn't a ``dtype`` argument still be useful? np.ceil(some_array).astype(int) That's one temporary more. The dtype= argument for all ufuncs wouldn't probably hurt too much. -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion