[Numpy-discussion] What type should / return in python 3k when applied to two integer types?

Charles R Harris charlesr.harris at gmail.com
Thu Aug 27 16:51:51 EDT 2009


On Thu, Aug 27, 2009 at 2:35 PM, <josef.pktd at gmail.com> wrote:
<snip>

>
> I'm always a bit surprised about integers in numpy and try to avoid
> calculations with them. So I would be in favor of x/y is correct
> floating point answer.
>
> Josef
>
> >>> x = np.ones(1, dtype=np.uint64); y = np.ones(1, dtype=np.int64)
> >>> np.true_divide((0*x),0)
> array([ 0.])
> >>> np.true_divide((0*x),0).dtype
> dtype('float64')
>
> >>> np.true_divide((0*x),0.)
> array([ NaN])
> >>> np.true_divide((x),0)
> array([ 0.])
> >>> np.true_divide((x),0.)
> array([ Inf])
>
> floor doesn't return an integer
>

floor_divide is different, it is supposed to correspond to the new python //
operator.

In [1]: x = ones(1, dtype=int16)

In [2]: floor_divide(x,x).dtype
Out[2]: dtype('int16')

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090827/a1c3acff/attachment.html>


More information about the NumPy-Discussion mailing list