I am trying to write a function which has the name my_within_tolerance(A, a, tol). A can be float list or array while a and tol are float numbers. The function should return the elements in A which are |A − a| < tol. I am facing issues writing the function. Please help me....
I am new to python.
Here is what I have written:
import numpy as np
def my_within_tolerance(A, a, tol):
A=np.asarray(A)
if((abs(A-a)<tol).any()):
return A
print(my_within_tolerance([0, 1, 2, 3], 1.5, 0.75))
Output should be:
[1, 2]