我正在尝试在大型 3D 数据集上运行此代码。目标是计算每个网格点与所有其他网格点的时间相关性(轴 0)。我想像下面的代码那样做:两个循环,每个维度一个。这对于小型数据集来说是可以的,但现在我转向更大的分辨率,并且需要几天的时间才能运行。
for lat in range(latitude.shape[0]):
print('-->lat_points = ' + str(lat) + '/' +
str(latitude.shape[0]))
for lon in range(longitude.shape[0]):
print ('lon_points = ' + str(lon) + '/' +
str(longitude.shape[0]))
corr = correlation(sub_cube1[:, lat, lon], sub_cube2)
rho[lat, lon] = corr.min()
vec_lat[lat, lon] = np.where(corr == corr.min())[0]
vec_lon[lat, lon] = np.where(corr == corr.min())[1]
任何人都可以建议加快/优化此代码,请记住我只能访问标准 python 库(所以没有 mpi4py!)?
correlation
函数用于pandas
计算两个时间序列之间的相关系数:
corr_coef = np.empty(shape=series1[0, ].shape)
for j in range(series1.shape[-2]):
for k in range(series1.shape[-1]):
apd = pd.Series(series1[:, j, k])
bpd = pd.Series(series2[:, j, k])
corr_coef[j, k] = apd.corr(bpd)
谢谢