[Numpy-discussion] Numpy integers to integer powers again again

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Oct 26 15:49:36 EDT 2016


On Wed, Oct 26, 2016 at 3:39 PM, Nathaniel Smith <njs at pobox.com> wrote:

> On Wed, Oct 26, 2016 at 12:23 PM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
> [...]
> > What I have been concerned about are the follow combinations that
> currently
> > return floats
> >
> > num: <type 'numpy.int8'>, exp: <type 'numpy.int8'>, res: <type
> > 'numpy.float32'>
> > num: <type 'numpy.int16'>, exp: <type 'numpy.int8'>, res: <type
> > 'numpy.float32'>
> > num: <type 'numpy.int16'>, exp: <type 'numpy.int16'>, res: <type
> > 'numpy.float32'>
> > num: <type 'numpy.int32'>, exp: <type 'numpy.int8'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int32'>, exp: <type 'numpy.int16'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int32'>, exp: <type 'numpy.int32'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int64'>, exp: <type 'numpy.int8'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int64'>, exp: <type 'numpy.int16'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int64'>, exp: <type 'numpy.int32'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int64'>, exp: <type 'numpy.int64'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.int64'>, exp: <type 'numpy.int64'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.uint64'>, exp: <type 'numpy.int8'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.uint64'>, exp: <type 'numpy.int16'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.uint64'>, exp: <type 'numpy.int32'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.uint64'>, exp: <type 'numpy.int64'>, res: <type
> > 'numpy.float64'>
> > num: <type 'numpy.uint64'>, exp: <type 'numpy.int64'>, res: <type
> > 'numpy.float64'>
>
> What's this referring to? For both arrays and scalars I get:
>
> In [8]: (np.array(2, dtype=np.int8) ** np.array(2, dtype=np.int8)).dtype
> Out[8]: dtype('int8')
>
> In [9]: (np.int8(2) ** np.int8(2)).dtype
> Out[9]: dtype('int8')
>


>>> (np.array([2], dtype=np.int8) ** np.array(-1,
dtype=np.int8).squeeze()).dtype
dtype('int8')
>>> (np.array([2], dtype=np.int8)[0] ** np.array(-1,
dtype=np.int8).squeeze()).dtype
dtype('float32')

>>> (np.int8(2)**np.int8(-1)).dtype
dtype('float32')
>>> (np.int8(2)**np.int8(2)).dtype
dtype('int8')

The last one looks like value dependent scalar dtype

Josef


>
> -n
>
> --
> Nathaniel J. Smith -- https://vorpus.org
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20161026/fce16342/attachment.html>


More information about the NumPy-Discussion mailing list