我想用当前值减去上一个值,但是我卡在3d数组中?
print(rain.shape) #(73,80,97)
for j in range(1,72):
diffrain=np.array(rain[j+1,:,:]-rain[j,:,:])
print(diffrain.shape) #(80,97) only 2d array what about j, here j.shape=73 after subtrcation the value of j will be 72.
我想要3d(72,80,97)中的diffrain.shape但显示2d数组。
答案 0 :(得分:0)
您为每个diffrain
重新分配了j
。而是
diffrain = []
for j in range(1,72):
diffrain.append(rain[j+1,:,:]-rain[j,:,:])
diffrain = np.stack(diffrain)
print(diffrain.shape) # now (72,80,97)