Skip to content

Commit 9da64d8

Browse files
authored
Merge pull request numpy#20213 from WarrenWeckesser/doc-power-neg
DOC: Mention `nan` results in `power` and `float_power`.
2 parents 851f5c4 + 7450ea3 commit 9da64d8

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

numpy/core/code_generators/ufunc_docstrings.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,8 +3065,14 @@ def add_newdoc(place, name, doc):
30653065
First array elements raised to powers from second array, element-wise.
30663066
30673067
Raise each base in `x1` to the positionally-corresponding power in
3068-
`x2`. `x1` and `x2` must be broadcastable to the same shape. Note that an
3069-
integer type raised to a negative integer power will raise a ValueError.
3068+
`x2`. `x1` and `x2` must be broadcastable to the same shape.
3069+
3070+
An integer type raised to a negative integer power will raise a
3071+
``ValueError``.
3072+
3073+
Negative values raised to a non-integral value will return ``nan``.
3074+
To get complex results, cast the input to complex, or specify the
3075+
``dtype`` to be ``complex`` (see the example below).
30703076
30713077
Parameters
30723078
----------
@@ -3121,6 +3127,21 @@ def add_newdoc(place, name, doc):
31213127
>>> x1 ** x2
31223128
array([ 0, 1, 8, 27, 16, 5])
31233129
3130+
Negative values raised to a non-integral value will result in ``nan``
3131+
(and a warning will be generated).
3132+
3133+
>>> x3 = np.array([-1.0, -4.0])
3134+
>>> with np.errstate(invalid='ignore'):
3135+
... p = np.power(x3, 1.5)
3136+
...
3137+
>>> p
3138+
array([nan, nan])
3139+
3140+
To get complex results, give the argument ``dtype=complex``.
3141+
3142+
>>> np.power(x3, 1.5, dtype=complex)
3143+
array([-1.83697020e-16-1.j, -1.46957616e-15-8.j])
3144+
31243145
""")
31253146

31263147
add_newdoc('numpy.core.umath', 'float_power',
@@ -3134,6 +3155,10 @@ def add_newdoc(place, name, doc):
31343155
inexact. The intent is that the function will return a usable result for
31353156
negative powers and seldom overflow for positive powers.
31363157
3158+
Negative values raised to a non-integral value will return ``nan``.
3159+
To get complex results, cast the input to complex, or specify the
3160+
``dtype`` to be ``complex`` (see the example below).
3161+
31373162
.. versionadded:: 1.12.0
31383163
31393164
Parameters
@@ -3181,6 +3206,21 @@ def add_newdoc(place, name, doc):
31813206
array([[ 0., 1., 8., 27., 16., 5.],
31823207
[ 0., 1., 8., 27., 16., 5.]])
31833208
3209+
Negative values raised to a non-integral value will result in ``nan``
3210+
(and a warning will be generated).
3211+
3212+
>>> x3 = np.array([-1, -4])
3213+
>>> with np.errstate(invalid='ignore'):
3214+
... p = np.float_power(x3, 1.5)
3215+
...
3216+
>>> p
3217+
array([nan, nan])
3218+
3219+
To get complex results, give the argument ``dtype=complex``.
3220+
3221+
>>> np.float_power(x3, 1.5, dtype=complex)
3222+
array([-1.83697020e-16-1.j, -1.46957616e-15-8.j])
3223+
31843224
""")
31853225

31863226
add_newdoc('numpy.core.umath', 'radians',

0 commit comments

Comments
 (0)