import numpy as np
list1 = ['1.1575', '1.1604', '1.1600', '1.1635', '1.1749', '1.1766', '1.1750', '1.1746', '1.1747', '1.1779']
list2 = ['6604.11341382', '6688.01480364', '6668.72146384', '6553.56452794', '6499.18728419', '6629.18122154', '6724.42744078', '6737.98000228', '6755.31691870', '6556.66000350']
list1=list(map(float,list1)) #convert into float
list2=list(map(float,list2))
# Method 2 (Correlation, p-value)
def pcc(x,y):
x = x - x.mean(0)
y = y - y.mean(0)
x /= x.std(0)
y /= y.std(0)
return np.mean(x*y)
print(pcc(np.array(list1),np.array(list2))) # pass numpy array
Вывод:
0.04183992052616166
ИЛИ Лучше хранить все в массиве
import numpy as np
list1 = ['1.1575', '1.1604', '1.1600', '1.1635', '1.1749', '1.1766', '1.1750', '1.1746', '1.1747', '1.1779']
list2 = ['6604.11341382', '6688.01480364', '6668.72146384', '6553.56452794', '6499.18728419', '6629.18122154', '6724.42744078', '6737.98000228', '6755.31691870', '6556.66000350']
list1 = np.array(list1).astype(np.float) # or np.asarray(list1, dtype=np.float64)
list2 = np.array(list2).astype(np.float)
# Method 2 (Correlation, p-value)
def pcc(x,y):
x = x - x.mean(0)
y = y - y.mean(0)
x /= x.std(0)
y /= y.std(0)
return np.mean(x*y)
print(pcc(list1,list2)) # directly pass numpy float arrays
Вывод
0.04183992052616166