Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-086

Binning Continuous Features

Problem

Bin continuous values given sorted interior edges: the bin index of v is the number of edges that are <= v.

Return the list of indices; empty values returns [].

Hint

Count how many edges are less than or equal to the value.

Test cases

case 1
in: [[0,1,2,3,4],[1,3]]
expected: [0,1,1,2,2]
case 2
in: [[5],[1,2,3]]
expected: [3]
case 3
in: [[-1,0,0.5],[0,0.5]]
expected: [0,1,2]
case 4
in: [[],[1]]
expected: []
Starter codePython
def bin_values(values, edges):
    # Your code here
    pass

4 test cases · run your code against them in the editor