Cody Bable

Generation

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.

import numpy as np def find_nearest(array,value): idx = (np.abs(array-value)).argmin() return array[idx] find_nearest([1,2,3,4,5,6,7,8,9],2.5)

Questions about programming?Chat with your personal AI assistant