MCPcopy Create free account
hub / github.com/numpy/numpy / power

Function power

numpy/lib/scimath.py:442–483  ·  view source on GitHub ↗

Return x to the power p, (x**p). If `x` contains negative values, the output is converted to the complex domain. Parameters ---------- x : array_like The input value(s). p : array_like of ints The power(s) to which `x` is raised. If `x` contains multipl

(x, p)

Source from the content-addressed store, hash-verified

440
441@array_function_dispatch(_power_dispatcher)
442def power(x, p):
443 """
444 Return x to the power p, (x**p).
445
446 If `x` contains negative values, the output is converted to the
447 complex domain.
448
449 Parameters
450 ----------
451 x : array_like
452 The input value(s).
453 p : array_like of ints
454 The power(s) to which `x` is raised. If `x` contains multiple values,
455 `p` has to either be a scalar, or contain the same number of values
456 as `x`. In the latter case, the result is
457 ``x[0]**p[0], x[1]**p[1], ...``.
458
459 Returns
460 -------
461 out : ndarray or scalar
462 The result of ``x**p``. If `x` and `p` are scalars, so is `out`,
463 otherwise an array is returned.
464
465 See Also
466 --------
467 numpy.power
468
469 Examples
470 --------
471 >>> np.set_printoptions(precision=4)
472
473 >>> np.emath.power([2, 4], 2)
474 array([ 4, 16])
475 >>> np.emath.power([2, 4], -2)
476 array([0.25 , 0.0625])
477 >>> np.emath.power([-2, 4], 2)
478 array([ 4.-0.j, 16.+0.j])
479
480 """
481 x = _fix_real_lt_zero(x)
482 p = _fix_int_lt_zero(p)
483 return nx.power(x, p)
484
485
486@array_function_dispatch(_unary_dispatcher)

Callers

nothing calls this directly

Calls 2

_fix_real_lt_zeroFunction · 0.85
_fix_int_lt_zeroFunction · 0.85

Tested by

no test coverage detected