correlation
numpy.corrcoef: Pearson product-moment correlation coefficients
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

Use numpy.ma.corrcoef for masked array
The Glowing Python: Visualizing correlation matrices

pandas.Series.corr
pandas.DataFrame.corr
pandas.DataFrame.corrwith

heatmap
Plotting a diagonal correlation matrix
Seaborn / Heatmap using Seaborn (order rows and columns as you like) - Qiita
clustermap
seaborn clustermap - nykergotos blog https://nykergoto.hatenablog.jp/entry/2018/11/19/seaborn__clustermap_

Multi-dimension
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)

from numpy.corrcoef returns 1 when applied on 2 matrices. · Issue '#4819 · numpy/numpy · GitHub

python - Computing the correlation coefficient between two multi-dimensional arrays - Stack Overflow

See also