What is the numpy.float_power() function from NumPy in Python?

Overview

The numpy.float_power() function in NumPy is used to return a result, such that each element of an array x1 is raised to the power of each element of another array x2.

Mathematically

numpy.float_power (x1,x2)=x1x2(x_1,x_2) = {x_1}^{x_2}

Syntax

numpy.float_power(x1, x2, /, out=None, *, where=True)
Syntax for the numpy.float_power() function

Parameter values

The numpy.float_power() function takes the following parameter values:

  • x1: This represents an input array whose elements are the bases. This is a required parameter value.
  • x2: This represents an array whose elements are the exponents. This is a required parameter value.
  • out: This represents the location where the result is stored. This is an optional parameter value.
  • where: This is the condition over which the input is being broadcast. At a given location where this condition is True, the resulting array will be set to the ufunc result. Otherwise, the resulting array will retain its original value. This is an optional parameter value.
  • **kwargs: This represents the other keyword arguments. This is an optional parameter value.
import numpy as np
# creating input arrays
x1 = np.array([1.1, 2.2, 3.6])
x2 = np.array([2.1, 1.1, 2.5])
# implementing the float_power() function
myarray = np.float_power(x1, x2)
print(x1)
print(x2)
print("The float_power values are: ", myarray)

Code explanation

  • Line 1: We import the numpy module.
  • Lines 4–5: We create the input arrays, x1 and x2\, using the array() function.
  • Line 7: We implement the numpy.float_power() function on the input arrays. We assign the result to a variable called myarray.
  • Lines 9–10: We print the input arrays x1 and x2to the console.
  • Line 11: We print the variable myarray to the console.