What is the numpy.reciprocal() function in NumPy?
numpy.reciprocal(x, /, out=None, *, where=True)
The syntax for the numpy.reciprocal() function
Parameter values
The numpy.reciprocal() function takes the following parameter values.
x: This represents input array and is a required parameter.out: This represents the location where the result is stored and is an optional parameter.where: This is the condition over which the input is being broadcast. The resulting array will be set to theufuncresult at a given location where this condition isTrue. Otherwise, the resulting array will retain its original value. This is an optional parameter.**kwargs: This represents other keyword arguments and is an optional parameter.
Example
import numpy as np# creating an arrayx = np.array([0.5, 1, 2])# implementing the numpy.reciprocal() functionmyarray = np.reciprocal(x)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array
xusing thearray()method. - Line 7: We implement the
np.reciprocal()function on the array. The result is assigned to a variable,myarray. - Line 9: We print the
myarrayvariable.