power
Description
Use each element in the first input as the base and each element in the second input as the exponent, and calculate the result, that is,
.
x1 and x2 must be broadcastable to the same shape. If x1[i] contains integers and x2[i] contains negative integers, the ValueError exception is thrown. If x1[i]<0 and elements in x2[i] are not integers, NaN is returned. To return a complex number, you need to convert the type of input data to complex or specify dtype=complex.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
x1 |
array_like |
Base, which is an input array or scalar |
x2 |
array_like |
Exponent, which is an input array or scalar If x1.shape!=x2.shape, they must be broadcastable to a common shape. |
Optional Input Parameters
Return Value
Type |
Description |
|---|---|
ndarray/scalar |
Result of the bases in x1 raised to the exponents in x2 |
Examples
>>> import numpy as np >>> np.power(3, 2) 9 >>> x1 = np.arange(6) >>> x1 array([0, 1, 2, 3, 4, 5]) >>> np.power(x1, 3) array([ 0, 1, 8, 27, 64, 125]) >>> >>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0] >>> np.power(x1, x2) array([ 0., 1., 8., 27., 16., 5.]) >>>
Parent topic: Basic Operation Functions