How to use the np.float_power() function for 2D array
What is numpy.float_power()?
The numpy.float_power() method gives a result that raises each element of the first array x1 to the power of each element of the second array x2.
Note: In Python, a list of lists can be used to create a two-dimensional (2-D) array.
Syntax
numpy.float_power(x1, x2, dtype=None, out=None)
Parameters
x1: array-like, which represents the data input.x2: array-like, which represents the data input.dtype: This is an optional parameter. It represents the array’s return type.out: This is an optional parameter. It denotes the alternate output array where the result will be stored.
Note: If
x1andx2have different shapes, they must be broadcastable to a common output shape.
Return value
The method numpy.float power() returns an array with x1 elements raised to exponents in x2.
Example
The following code shows how to use the numpy.float_power() method for 2-D arrays.
# import numpyimport numpy as np# create a two 2D arraysx1 = np.array([[2,7,3,9],[6,2,5,8]])x2 = np.array([[5,4,6,11],[2,9,10,1]])# compute the power of the 2D arrays# and store the result in resres = np.float_power(x1, x2)print(res)
Explanation
- Line 2: We import the
numpylibrary. - Line 4–5: We create the
x1andx22-D arrays. - Line 9: To compute the power of the arrays
x1andx2, we utilize thenp.float_power()function. The outcome is saved in a new variable namedres. - Line 11: We display the result.