You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用xarray分位数函数生成的DataArray处理性能低下问题

xarray quantile处理分块DataArray后性能异常问题

我发现使用xarray内置的quantile函数处理分块DataArray得到的新DataArray,在访问或绘图时性能极低,耗时远高于同尺寸、同分块模式的其他DataArray。

示例说明

我编写了一段脚本,对比从同一3D随机样本DataArray衍生出的两个2D DataArray的绘图耗时:一个是时间切片数组,另一个是按时间维度计算分位数得到的数组。尽管两者尺寸、分块模式和数据类型均一致,但脚本执行耗时差异显著。

在我的研究数据集中,绘制单个分位数数组耗时超30分钟,而绘制切片数组耗时不到1分钟。目前尚未找到解决该问题的有效方案。

测试脚本

以下是展示耗时差异的测试脚本(使用xarray 2023.7.0版本):

# 模块导入
import xarray as xr
import datetime
import matplotlib.pyplot as plt
import numpy as np

# 样本数据
test = xr.DataArray(data=np.random.rand(500,500,500),
                  coords={"x": list(range(500)), "y": list(range(500)), 'time':list(range(500))},
                  dims=("x", "y", 'time')).chunk('auto')

test1 = test.sel(time=0)
test2 = test.chunk(dict(time=-1)).quantile(0.5, dim='time', skipna=True)

# 绘制test1并计时
start = datetime.datetime.now()
plt.figure()
test1.plot()
end = datetime.datetime.now()
time_taken = end - start
print('绘制test1耗时', time_taken)

# 绘制test2并计时
start = datetime.datetime.now()
plt.figure()
test2.plot()
end = datetime.datetime.now()
time_taken = end - start
print('绘制test2耗时', time_taken)

内容的提问来源于stack exchange,提问作者Name_is_Newton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 16:32:15