MCPcopy Index your code
hub / github.com/numpy/numpy / power

Function power

numpy/lib/_scimath_impl.py:441–491  ·  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

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

Callers 3

__pow__Method · 0.70
__rpow__Method · 0.70
__ipow__Method · 0.70

Calls 2

_fix_real_lt_zeroFunction · 0.85
_fix_int_lt_zeroFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…