[Numpy-discussion] Integers to negative integer powers, time for a decision.

Krisztián Horváth raksi.raksi at gmail.com
Sat Oct 8 18:18:45 EDT 2016

but then that violates the numpy
> principle that output dtypes should be determined entirely by input
> dtypes, without peeking at the actual values. (And this rule is very
> important for avoiding nasty surprises when you run your code on new
> inputs.)
At division you get back an array of floats.

>>> y = np.int64([1,2,4])
>>> y/1
array([ 1.,  2.,  4.])
>>> y/y
array([ 1.,  1.,  1.])

Why is it different, if you calculate the power of something?

> And then there's backwards compatibility to consider. As mentioned, we
> *could* deviate from Python by making ** always return float... but
> this would almost certainly break tons and tons of people's code that
> is currently doing integer ** positive integer and expecting to get an
> integer back. Which is something we don't do without very careful
> weighing of the trade-offs, and my intuition is that this one is so
> disruptive we probably can't pull it off. Breaking working code needs
> a *very* compelling reason.
This is a valid reasoning. But it could be solved with raising an exception
to warn the users for the new behaviour.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20161009/8a3ea604/attachment.html>

More information about the NumPy-Discussion mailing list