I'm making a correlation matrix on a timeseries, by looping over indexes of the matrix. Currently, my code is
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
Is there a better/more efficient way to do this? Thanks.