Q:

Write a NumPy program to find the nearest value from a given value in an array

0

Write a NumPy program to find the nearest value from a given value in an 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.random.uniform(1, 12, 5)
v = 4
n = x.flat[np.abs(x - v).argmin()]
print(n)

Sample Output:

4.2507132388

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