[Numpy-discussion] Integers to integer powers, let's make a decision

Allan Haldane allanhaldane at gmail.com
Mon Jun 13 13:07:53 EDT 2016


On 06/13/2016 05:05 AM, V. Armando Solé wrote:
> On 11/06/2016 02:28, Allan Haldane wrote:
>>
>> So as an extra twist in this discussion, this means numpy actually
>> *does* return a float value for an integer power in a few cases:
>>
>>      >>> type( np.uint64(2) ** np.int8(3) )
>>      numpy.float64
>>
> 
> Shouldn't that example end up the discussion? I find that behaviour for
> any integer power of an np.uint64. I guess if something was to be
> broken, I guess it is already the case.
> 
> We were given the choice between:
> 
> 1 - Integers to negative integer powers raise an error.
> 2 - Integers to integer powers always results in floats.
> 
> and we were never given the choice to adapt the returned type to the
> result. Assuming that option is not possible, it is certainly better
> option 2 than 1 (why to refuse to perform a clearly defined
> operation???) *and* returning a float is already the behaviour for
> integer powers of np.uint64.

Not for any uints: "type( np.uint64(2) ** np.uint8(3) )" is uint64.

Although I brought it up I think the mixed dtype case is a bit of a red
herring. The single-dtype case is better to think about for now, eg
"np.uint64(2) ** np.uint64(3)".

Allan



More information about the NumPy-Discussion mailing list