All problems
Convex Combination Check
Problem
Return True if the weights form a convex combination: every weight is non-negative and the weights sum to 1, both within a tolerance of 1e-9. Otherwise return False.
Hint
A convex combination is an affine combination with no negative weights.
Test cases
case 1
in: [[0.5,0.5]]
expected: true
case 2
in: [[0.2,0.3,0.5]]
expected: true
case 3
in: [[1.2,-0.2]]
expected: false
case 4
in: [[0.5,0.6]]
expected: false
case 5
in: [[1]]
expected: true
Starter codePython
def is_convex_combination(weights):
# Your code here
pass5 test cases · run your code against them in the editor