Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python xarray select \插入自定义1D切片auf多维数据(又名zip vs itertools.product)_Python_Multidimensional Array_Python Xarray - Fatal编程技术网

Python xarray select \插入自定义1D切片auf多维数据(又名zip vs itertools.product)

Python xarray select \插入自定义1D切片auf多维数据(又名zip vs itertools.product),python,multidimensional-array,python-xarray,Python,Multidimensional Array,Python Xarray,我有一个(大的)多维xarray数据数组或数据集,希望沿着1D路径选择或插值数据,而不需要缓慢的for循环或列表理解(例如,在纬度和经度上定义了2D数据,我希望沿着纬度和经度给定的路径获取数据): 下面返回一个2D数据数组,该数组包含path_lats和path_lons的所有组合,类似于使用itertools.product(path_lats,path_lons)的for循环: 对于大于二维的较大Dataarrays \数据集,这将消耗大量内存,因为它包含许多此任务不需要的数据 我想要的是使

我有一个(大的)多维xarray数据数组或数据集,希望沿着1D路径选择或插值数据,而不需要缓慢的for循环或列表理解(例如,在纬度和经度上定义了2D数据,我希望沿着纬度和经度给定的路径获取数据):

下面返回一个2D数据数组,该数组包含path_lats和path_lons的所有组合,类似于使用itertools.product(path_lats,path_lons)的for循环:

对于大于二维的较大Dataarrays \数据集,这将消耗大量内存,因为它包含许多此任务不需要的数据

我想要的是使用zip(path_lats,path_lons)的for-loop\list理解的快速版本,例如类似(此处的语法无效)

这将返回一个1D数据数组(坐标:路径索引),可能还有数据之外的纬度和经度。生成的数据阵列应包含以下数据:

[float(da.interp(latitude=p_lat, longitude=p_lon)) for p_lat, p_lon in zip(path_lats, path_lons)]

在xarray中不使用循环就可以做到这一点吗?

不过,我只是在以下目录中找到了解决方案:

da_path = da.interp(latitude=path_lats, longitude=path_lons)
da_pathZIP = da.interp((latitude, longitude) = (path_lats, path_lons))
[float(da.interp(latitude=p_lat, longitude=p_lon)) for p_lat, p_lon in zip(path_lats, path_lons)]
da_lons = xr.DataArray(path_lons, dims='time')
da_lats = xr.DataArray(path_lats, dims='time')
da_pathZIP = da.interp(latitude=da_lats, longitude=da_lons)