简体   繁体   English

Python:两个二维arrays之间的相关系数

[英]Python : Correlation coefficient between two 2D arrays

Let's assume that we have two different 2D np.arrays假设我们有两个不同的 2D np.arrays

a = (np.random.randint(25,30,1512000)).reshape(1050,1440)

b = (np.random.randint(20,25,1512000)).reshape(1050,1440)

So, the dimension of a and b is (1050,1440)所以, ab的维度是(1050,1440)

I want to calculate the cross correlation coefficient between a and b at each grid point (ie to create a new 2D array containing correlation coefficient values between a and b, with a dimension of (1050,1440).我想计算每个网格点 a 和 b 之间的互相关系数(即创建一个新的二维数组,其中包含 a 和 b 之间的相关系数值,维度为 (1050,1440)。

You can do this with nctoolkit.你可以用 nctoolkit 做到这一点。 Assuming the files have the same grid, the following will work:假设文件具有相同的网格,以下将起作用:

import nctoolkit as nc
ds1 = nc.open_data("file1.nc")
ds2 = nc.open_data("file2.nc")
ds_cor = nc.cor_space(ds1, ds2)
ds_cor.plot()

Likely the grids do not match, so you might want to regrid:可能网格不匹配,因此您可能需要重新网格化:

import nctoolkit as nc
ds1 = nc.open_data("file1.nc")
ds2 = nc.open_data("file2.nc")
# regrid ds1 to ds2's grid
ds1.regrid(ds2)
ds_cor = nc.cor_space(ds1, ds2)
ds_cor.plot()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM