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

Nathaniel Smith njs at pobox.com
Wed Oct 26 15:39:15 EDT 2016


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')

-n

-- 
Nathaniel J. Smith -- https://vorpus.org



More information about the NumPy-Discussion mailing list