What is the numpy.frexp() function in NumPy?
numpy.frexp(x, out1, out2, out=None, *, where=True)
Syntax for the numpy.frexp() function
Parameter value
x: This is the input array of numbers to be decomposed. It is a required parameter.out1: This is the output array for the mantissa. It must have the same shape as the input array, x. It is an optional parameter.out2: This is the output array for the exponent. It must have the same shape as the input array, x. It is an optional parameter.out: This represents the location where the result is stored. It is an optional parameter. where: This is the condition over which the input is being broadcast. The resulting array will be set to the ufunc result at a given location where this condition is True. Otherwise, the resulting array will retain its original value. It is an optional parameter.**kwargs: This represents other keyword arguments. It is an optional parameter.Return value
The numpy.frexp() function returns an output array showing an array of mantissa values for each element, and another array of
Example
import numpy as np# creating an arrayx = np.array([1, 2, 3, 4, 5])# obtaining the frexp valuesmyarray = np.frexp(x)print("Input: " , x)print("Mantissas : ", myarray[0])print("Exponents : ", myarray[1])
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an input array of values called
x. - Line 7: We implement the
numpy.frexp()function on the arrayx. We assign the result to a variablemyarray. - Line 9: We print the input array
xto the console. - Line 10: We print the variable
myarrayto the console.