[Numpy-discussion] Integers to negative integer powers, time for a decision.
V. Armando Sole
sole at esrf.fr
Sat Oct 8 16:40:51 EDT 2016
Well, testing under windows 64 bit, Python 3.5.2, positive powers of
integers give integers and negative powers of integers give floats. So,
do you want to raise an exception when taking a negative power of an
element of an array of integers? Because not doing so would be
inconsistent with raising the exception when applying the same operation
to the array.
Clearly things are broken now (I get zeros when calculating negative
powers of numpy arrays of integers others than 1), but that behavior was
consistent with python itself under python 2.x because the division of
two integers was an integer. That does not hold under Python 3.5 where
the division of two integers is a float.
You have offered either to raise an exception or to always return a
float (i.e. even with positive exponents). You have never offered to be
consistent with what Python does. This last option would be my favorite.
If it cannot be implemented, then I would prefer always float. At least
one would be consistent with something and we would not invent yet
another convention.
On 08.10.2016 21:36, Charles R Harris wrote:
> On Sat, Oct 8, 2016 at 1:31 PM, Krisztián Horváth
> <raksi.raksi at gmail.com> wrote:
>
>> Hello,
>>
>> I think it should be consistent with Python3. So, it should give
>> back a float.
>>
>> Best regards,
>> Krisztian
>
> Can't do that and also return integers for positive powers. It isn't
> possible to have behavior completely compatible with python for
> arrays: can't have mixed type returns, can't have arbitrary precision
> integers.
>
> Chuck
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list