【发布时间】:2020-12-26 04:47:09
【问题描述】:
我想创建一个 3 维数据数组,该数组存储具有相应纬度和经度的温度数据以及每小时频率的时间。所以我做了如下编码;
np.random.seed(123)
temperature_3d = 15 + 10 * np.random.randn(24,4,4) # 3-dimensional
lat = np.random.uniform(low=-90, high=90, size=(1,4))
lon = np.random.uniform(low=-180, high=180, size=(1,4))
# round to two digits after decimal point
temperature_3d = np.around(temperature_3d, decimals=2)
lat , lon = np.around([lat, lon], decimals=2)
date_rng = pd.date_range(start='1/1/2018T01:00', end='1/2/2018', freq='H')
da = xr.DataArray(data=temperature_3d,
coords={"lat": (["x","y"], lat),
"lon": (["x","y"], lon),
"day": date_rng},
dims=["x","y","day"])
da
我得到了这个错误,
ValueError: conflicting sizes for dimension 'x': length 24 on the data but length 1 on coordinate 'lat'
在维度上它是错误的,我可以在不包括时间的情况下修复它,我的目标是创建一个具有 720x40x40 维度(timexlat,lonxtime)的数据数组。
我也是这类图书馆的新手。因此,我将不胜感激。
【问题讨论】:
标签: python pandas numpy multidimensional-array python-xarray