All problems
Vector Subtraction
Problem
Subtract two equal-length vectors elementwise.
Return a new list where the i-th entry is a[i] - b[i]. Both inputs always have the same length.
Hint
Zip the vectors and subtract the paired entries.
Test cases
case 1
in: [[1,2,3],[4,5,6]]
expected: [-3,-3,-3]
case 2
in: [[0,0],[0,0]]
expected: [0,0]
case 3
in: [[5],[7]]
expected: [-2]
case 4
in: [[1.5,-2],[0.5,0.5]]
expected: [1,-2.5]
case 5
in: [[-1,0,2],[-3,-4,-5]]
expected: [2,4,7]
Starter codePython
def vector_subtract(a, b):
# Your code here
pass5 test cases · run your code against them in the editor