![]() |
VOOZH | about |
numpy.power() is used to raise each element of one array (arr1) to the power of the corresponding element of another array (arr2). The operation happens element-wise, and both arrays must have the same shape.
Example:
Input: arr1 = arr2 = [2, 3, 4]
Output: [4, 27, 256]
(Each element is raised to the power of itself -> 2², 3³, 4⁴)
numpy.power(arr1, arr2, out=None, where=True, casting='same_kind', order='K', dtype=None)
Parameters:
Example 1: This example raises each element in a to the power of the corresponding element in b.
[ 4 8 16 32 64]
Explanation:np.power(a, b) -> computes 2**2, 2**3, 2**4, 2**5, 2**6
Example 2: This example generates an array using np.arange() and raises all its elements to the same exponent (a scalar value).
[ 0 1 4 9 16 25 36 49]
Explanation:
Example 3: This example shows how to correctly compute powers when the exponent array contains negative values.
[ 4. 0.125 16. ]
Explanation: