簡體   English   中英

Bilerping 2D python數組會產生比預期更多的值。 有誰能解釋一下?

[英]Bilerping a 2D python array results in more values than expected. Can anyone explain this?

當我運行下面的代碼時,我得到(24,170,180)(29559,)

作為我的打印語句的答案(打印數組的形狀)。 我使用的原始數據集的形狀是(24,170,180)。 因此,當前數據集dataArr的尺寸為170 * 180。 我修復了時間t = 10(這里有維度24)我迭代2d數組並且bilerp一個單元格(四個數據點-i,j i + 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得到的正確的點數,即:168 * 178

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM