All problems
Cross-Correlation Vector
Problem
Compute the cross-correlation vector between two equal-length series for lags k = 0, ..., h: the Pearson correlation of x[0..n-k-1] with y[k..n-1].
Return 0.0 at lags with fewer than two paired points or zero variance, and an empty list if the lengths differ or h < 0.
Hint
Positive lags compare earlier x values with later y values.
Test cases
case 1
in: [[1,2,3,4,5],[2,4,6,8,10],2]
expected: [0.9999999999999998,0.9999999999999998,0.9999999999999998]
case 2
in: [[1,2,3,4,5],[5,4,3,2,1],1]
expected: [-0.9999999999999998,-0.9999999999999998]
case 3
in: [[1,2,3],[3,2,1],0]
expected: [-0.9999999999999998]
case 4
in: [[1,1,1],[1,2,3],1]
expected: [0,0]
Starter codePython
def cross_correlation(x, y, h):
# Your code here
pass4 test cases · run your code against them in the editor