numpy 连接后出现新值

new values appear after numpy concatenate

我从 netcdf 文件加载数据。原始数据包含一些1.e+15的值,我定义为Nan:

from netCDF4 import Dataset
import numpy as np

t = Dataset('temperature.nc', 'r').variables['t'][0]
ind = np.where(t==1.E15)
t[ind] = np.nan

现在我想将数据移动到另一个经度坐标,所以我进行拆分和连接:

#first split data 
a1, a2 = np.split(t, 2, axis=2)
# print out max, min values of a1 and a2
print a1.max(), a1.min()
print a2.max(), a2.min()
# then concatenate with another order (a2 before a1)
new = np.concatenate((a2, a1), axis=2)
# print max, min value of new array after concatenating
print new.max(), new.min()

然而,我在屏幕上得到了结果:

313.69 181.438
313.69 181.407

1e+15 181.407

这意味着连接后的新数组再次包含 1E15 的值,我不明白为什么。任何人都可以解释我做错了什么。提前致谢!

您正在进行浮点数比较; 1.00000000001e15 != 1.000000000000e15;所以这通常不会起作用。请改用 np.where(t>=1e15) 之类的内容。