我通过循环矩阵的索引在时间序列上建立相关矩阵。目前,我的代码是
def make_correlation_matrix(ts):
num_regions = ts.shape[0]
corr_mat = np.zeros((num_regions, num_regions))
for i in range(num_regions):
for j in range(num_regions):
corr_mat[i,j] = np.correlate(ts[i,:], ts[j,:])
return corr_mat
有更好/更有效的方法吗?感谢。