Home > Mobile >  How to calculate correlation of column with different number of rows?
How to calculate correlation of column with different number of rows?

Time:10-09

Example

a1 = [1,2,3,4,5]
a2 = [2,3,5,6]

How to calculate correlation coefficient of this types of columns

CodePudding user response:

Trimming the lists to a common length and using numpy.corrcoeff:

a1 = [1,2,3,4,5]
a2 = [2,3,5,6]

n = min(len(a1), len(a2))

r = np.corrcoef(a1[:n], a2[:n])[0, 1]

Output: 0.9899494936611666

  • Related