Facebook Page Twitter Page LinkedIn Page
× NumPy Tutorial NumPy Resources

The NumPy reciprocal() function is used to return the reciprocal of the argument, element-wise. The syntax for using this function is given below:

Note: It is equivalent to 1/x in terms of array broadcasting.


numpy.reciprocal(x, out=None, dtype=None)


x Required. Specify the input array.
out Optional. Specify 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.
dtype Optional. Specify the desired data type of returned array.

Return Value

Returns reciprocal of the input array, element-wise.


The below example shows the usage of reciprocal() function.

import numpy as np
Arr = np.array([[2,4],[5,10]])

print("Arr is:")

#reciprocal of Arr
print("\nReciprocal array is:")
print(np.reciprocal(Arr, dtype=float))

The output of the above code will be:

Arr is:
[[ 2  4]
 [ 5 10]]

Reciprocal array is:
[[0.5  0.25]
 [0.2  0.1 ]]

❮ NumPy - Functions