[Numpy-discussion] Proposal to make power return float, and other such things.

Robert Kern robert.kern at gmail.com
Tue Feb 18 06:57:21 EST 2014


On Tue, Feb 18, 2014 at 11:44 AM, Sturla Molden <sturla.molden at gmail.com> wrote:
> Robert Kern <robert.kern at gmail.com> wrote:
>
>> We're talking about numpy.power(), not just ndarray.__pow__(). The
>> equivalence of the two is indeed an implementation detail, but I do
>> think that it is useful to maintain the equivalence. If we didn't, it
>> would be the only exception, to my knowledge.
>
> But in this case it makes sence.

Every proposed special case we come up with "makes sense" in some way.
That doesn't mean that they are special enough to break the rules. In
my opinion, this is not special enough to break the rules. In your
opinion, it is.

> math.pow(2,2) and 2**2 does not do the same. That is how Python behaves.

Yes, because the functions in the math module are explicitly thin
wrappers around floating-point C library functions and don't have any
particular relationship to the special methods on int objects. numpy
does have largely 1:1 relationship between its ndarray operator
special methods and the ufuncs that implement them. I believe this is
a useful relationship for learning the API and predicting what a given
expression is going to do.

-- 
Robert Kern



More information about the NumPy-Discussion mailing list