Cody Bable


generate functionTue, 23 May 2023

create a function of a set of integers and a value for which you need to find the nearest one.

def find_nearest(value, array): idx = (np.abs(array-value)).argmin() return array[idx] my_array = np.arange(0, 10, 0.5) value = 3.4 find_nearest(value, my_array)

Questions about programming?Chat with your personal AI assistant