numpy.reciprocal(x, /, out=None, *, where=True) : This mathematical function is used to calculate reciprocal of all the elements in the input array.
x[array_like]: Input array or object whose elements needed to test.
out [ndarray, optional]: A location into which the result is stored.
–> If provided, it must have a shape that the inputs broadcast to.
–> If not provided or None, a freshly-allocated array is returned.
**kwargs : Allows to pass keyword variable length of argument to a function. Used when we want to handle named argument in a function.
where [array_like, optional]: True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.
y : ndarray. This is a scalar if x is a scalar.
Note: For integer arguments with absolute value larger than 1, the result is always zero because of the way Python handles integer division. For integer zero the result is an overflow.
Code #1 :
Input number : 2.0 Output number : 0.5
Code #2 :
Input array : [2.0, 3.0, 8.0] Output array : [ 0.5 0.33333333 0.125 ]
Code #3 : Exception in reciprocal() function. Result is always zero.
Input array : [2, 3, 8] Output array : [0 0 0]
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Index of Non-Zero elements in Python list
- Python | Merge Python key values to list
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Python Set | pop()
- Use of min() and max() in Python
- pow() in Python
- zip() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.