pandas
>pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.https://pandas.pydata.org/[** Tutorials]
from numpy import np
T = np.array([1.3, 4.5, 2.8, 3.9])
P = np.array([2.7, 8.7, 4.7, 8.2])
print(np.corrcoef([T,P]))
rho = np.array([8.5, 5.2, 6.9, 6.5])
data = np.column_stack([T,P,rho])
print(np.corrcoef([T,P,rho])) # correlation matrix of T,P and rho
def calculate_correlation_nd(data1, data2, axis = 0):
nt = data1.shape[axis]
assert data1.shape == data2.shape
view1 = data1
view2 = data2
if axis:
view1 = np.rollaxis(data1, axis)
view2 = np.rollaxis(data2, axis)
data1_norm = (view1 - data1.mean(axis=axis)) / data1.std(axis=axis)
data2_norm = (view2 - data2.mean(axis=axis)) / data2.std(axis=axis)
return np.sum(data1_norm * data2_norm / float(nt), axis=0)