All problems
Vector Addition
Problem
Compute the elementwise sum of two vectors a and b.
Both vectors have the same length. Return a new list c where c[i] = a[i] + b[i].
Hint
Pair the components with zip and add each pair.
Test cases
case 1
in: [[1,2,3],[4,5,6]]
expected: [5,7,9]
case 2
in: [[0,0],[1,-1]]
expected: [1,-1]
case 3
in: [[-2,5],[2,-5]]
expected: [0,0]
case 4
in: [[1.5,-2.5],[0.5,1.5]]
expected: [2,-1]
Starter codePython
def add_vectors(a, b):
# Your code here
pass4 test cases · run your code against them in the editor