All problems
Hard Negative Mining by Distance
Problem
Return the index of the hardest negative: among samples with label 0, the one with the smallest distance (ties keep the smallest index).
Return -1 if there is no negative sample.
Hint
The hardest negative is the one that is closest to the anchor.
Test cases
case 1
in: [[0.9,0.2,0.5,0.1],[0,1,0,0]]
expected: 3
case 2
in: [[0.1,0.2],[1,1]]
expected: -1
case 3
in: [[0.5,0.5],[0,0]]
expected: 0
Starter codePython
def hard_negative_index(distances, labels):
# Your code here
pass3 test cases · run your code against them in the editor