Q:

Write a NumPy program to compute the reciprocal for all elements in a given array

0

Write a NumPy program to compute the reciprocal for all elements in a given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([1., 2., .2, .3])
print("Original array: ")
print(x)
r1 = np.reciprocal(x)
r2 = 1/x
assert np.array_equal(r1, r2)
print("Reciprocal for all elements of the said array:")
print(r1)

Sample Output:

Original array: 
[1.  2.  0.2 0.3]
Reciprocal for all elements of the said array:
[1.         0.5        5.         3.33333333]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now