All problems
Affine Combination Check
Problem
Return True if the given weights form an affine combination, meaning they sum to 1 within a tolerance of 1e-9. Otherwise return False.
Hint
Only the sum of the weights matters for an affine combination.
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,1]]
expected: false
case 4
in: [[1]]
expected: true
Starter codePython
def is_affine_combination(weights):
# Your code here
pass4 test cases · run your code against them in the editor