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)
| 439 | @set_module('numpy.lib.scimath') |
| 440 | @array_function_dispatch(_power_dispatcher) |
| 441 | def 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') |
no test coverage detected
searching dependent graphs…