Write a NumPy program to find the nearest value from a given value in an array.
import numpy as np x = np.random.uniform(1, 12, 5) v = 4 n = x.flat[np.abs(x - v).argmin()] print(n)
Sample Output:
4.2507132388
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer