Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对2D python数组进行二倍化会产生比预期更多的值。有人能解释一下吗?_Python_Arrays_Numpy_Netcdf - Fatal编程技术网

对2D python数组进行二倍化会产生比预期更多的值。有人能解释一下吗?

对2D python数组进行二倍化会产生比预期更多的值。有人能解释一下吗?,python,arrays,numpy,netcdf,Python,Arrays,Numpy,Netcdf,当我运行下面的代码时,我得到 (24, 170, 180) (29559,) 作为我的打印语句(打印数组的形状)的答案。 我使用的原始数据集的形状是(24170180)。因此,当前数据集dataArr的维度为170*180。我将时间t=10(此处的维度为24)固定为一个值,并将二维数组和单元格(四个数据点-I,ji+1,j,I,j+1,I+1,j+1)迭代并附加到self.tempY数组中。因此,对于self.tempY数组的形状,我应该得到的值是170*180。但结果集有29904个值。为什么

当我运行下面的代码时,我得到 (24, 170, 180) (29559,)

作为我的打印语句(打印数组的形状)的答案。 我使用的原始数据集的形状是(24170180)。因此,当前数据集dataArr的维度为170*180。我将时间t=10(此处的维度为24)固定为一个值,并将二维数组和单元格(四个数据点-I,ji+1,j,I,j+1,I+1,j+1)迭代并附加到self.tempY数组中。因此,对于self.tempY数组的形状,我应该得到的值是170*180。但结果集有29904个值。为什么我会得到这个值

def compute(self,varval):      
    vars=self.data.variables
    for var in vars:
        if var==varval:
            ntimes, ny, nx=vars[var].shape #inherit the method above.
    print(ntimes, ny, nx)
    #create the old computational grid.
    computational_grid=np.zeros((ny,nx),dtype=int) 
    fraction=.5 
    newnx,newny =(nx*fraction,ny*fraction)
    new_computational_grid=np.zeros((newny,newnx),dtype=int)
    phy_value_arr=self.get_data(varval)
    t=10 #send this t value with coords
    dataArr=self.data.variables['tos'][t]     
    for j in range(1,(nx-2),1):
        for i in range(1,(ny-2),1):
           a=self.Lerp((dataArr[i][j+1]),(dataArr[i+1][j+1]),fraction)
           b=self.Lerp((dataArr[i][j]),(dataArr[i+1][j]),fraction)
           self.tempY.append(self.Lerp(a,b,fraction))
    smallgridarray = np.asarray(self.tempY)
    print(smallgridarray.shape)
def Lerp(self, _a, _b, _t) :
  return _a+(_b-_a)*_t    

好吧,我知道为什么了!这是我从nx-2*ny-2获得的正确点数
i、 e:168*178

你能提供一些输入数据的例子吗?我们如何调用此方法来自己检查结果?给定输入的预期输出是什么?我在这个方法中使用了一个netcdf数据集。它有几个变量,其中tos是我关心的变量。get_data(varval)是一个由时间经度和纬度组成的3d数组。我从3d数组中得到一个切片,其中t=10,并尝试得到2d平面中单元的平均值。这个平面的形状是170*180,有那么多点。我试图在这个平面上对每个单元格进行bilerp,并生成值数组。这有用吗?我打印了nx值和ny值,它们是180和170。如果我打印数据,我会得到这样的结果。我想知道空白值是否也有任何问题。[------------------] [---------------] [[------------]…],[271.42236328125 271.422607421875,271.4228820800781…,271.4221496582031 271.4220886230469 271.4221496582031 ][271.432373046875 271.43243408203125 271.4325256347656 ..., 271.4322204589844 271.4322814941406 271.4323425292969] [271.4455261230469 271.4455261230469 271.4455261230469 ..., 271.445556640625 271.445556640625 271.445556640625]]