[Numpy-discussion] Integers to integer powers

Eric Moore ewm at redtetrahedron.org
Tue May 24 15:57:53 EDT 2016


Yes, I'm fully aware of that.  I'm speaking toward changing the default
result dtype.  Raising an error for negative exponents is a fine idea.
Changing np.arange(10)**3 to have a non-integer dtype seems like a big
change.

Speaking of this, that some of the integer array operation errors can be
controlled via the np.seterr and some cannot should also be addressed
longer term.

Eric

On Tue, May 24, 2016 at 3:05 PM, Nathaniel Smith <njs at pobox.com> wrote:

> On Tue, May 24, 2016 at 10:36 AM, Eric Moore <ewm at redtetrahedron.org>
> wrote:
> > I'd say the most compelling case for it is that is how it has always
> worked.
> > How much code will break if we make that change? (Or if not break, at
> least
> > have a change in dtype?)  Is that worth it?
>
> The current behavior for arrays is:
>
> # Returns int
> In [2]: np.arange(10) ** 2
> Out[2]: array([ 0,  1,  4,  9, 16, 25, 36, 49, 64, 81])
>
> # Returns nonsensical/useless results
> In [3]: np.arange(10) ** -1
> /home/njs/.user-python3.5-64bit/bin/ipython:1: RuntimeWarning: divide by
> zero encountered in power
>   #!/home/njs/.user-python3.5-64bit/bin/python3.5
> /home/njs/.user-python3.5-64bit/bin/ipython:1: RuntimeWarning: invalid
> value encountered in power
>   #!/home/njs/.user-python3.5-64bit/bin/python3.5
> Out[3]:
> array([-9223372036854775808,                    1,                    0,
>                           0,                    0,                    0,
>                           0,                    0,                    0,
>                           0])
>
> -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/20160524/5b98d0b8/attachment.html>


More information about the NumPy-Discussion mailing list