将xarray数据数组的一部分转换为NumPy数组

2024-05-14 12:57:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我的DataArray太大,无法转换为NumPy数组:

da = xr.open_dataset('tprate.grib', engine='cfgrib').tprate
da.values

我得到:

Unable to allocate 8.56 TiB for an array with shape (28, 7008, 185, 180, 360) and data type float32

如果Iisel是DataArray的前两个维度的一部分,则它能够转换:

ncep_da.isel(number=0, time=0).values

但如果Iisel最后两个维度,使用的内存保持不变:

ncep_da.isel(latitude=0, longitude=0).values

我仍然得到:

Unable to allocate 8.56 TiB for an array with shape (28, 7008, 185, 180, 360) and data type float32

我猜这是因为第二个子数组没有顺序存储在磁盘上,因为最右边的维度是数据的内环

有没有办法提取第二个子数组并将其高效地转换为NumPy数组


Tags: tonumpyanforwith数组arrayda

热门问题