[Numpy-discussion] return value of negative power

Stefan van der Walt stefan at sun.ac.za
Thu Sep 28 05:29:27 CDT 2006

Hi all,

Currently, the power function returns '0' for negative powers of

In [1]: N.power(3,-2)
Out[1]: 0

(or, more confusingly)

In [1]: N.power(a,b)
Out[1]: 0

which is almost certainly not the answer you want.  Two possible
solutions may be to upcast the input to float before calculation, or
to return nan.

This would be consistent with a function like sqrt:

In [10]: N.sqrt(3)
Out[10]: 1.7320508075688772

In [11]: N.sqrt(-3)
Out[11]: nan

Does anyone have an opinion on whether the change is necessary, and if
so, on which one would work best?


More information about the Numpy-discussion mailing list