findnearest#
- findnearest(series=None, value=None)[source]#
Return the index of the nearest match in series to value – like
sc.findinds()
, but always returns an object with the same type as value (i.e. findnearest with a number returns a number, findnearest with an array returns an array).- Parameters:
series (array) – the array of numbers to look for nearest matches in
value (scalar or array) – the number or numbers to compare against
Examples:
sc.findnearest(rand(10), 0.5) # returns whichever index is closest to 0.5 sc.findnearest([2,3,6,3], 6) # returns 2 sc.findnearest([2,3,6,3], 6) # returns 2 sc.findnearest([0,2,4,6,8,10], [3, 4, 5]) # returns array([1, 2, 2])