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

Uproot 4读取非均匀直方图Bin Edges异常(版本差异问题)

Uproot 4.0.0读取非均匀Bin直方图边缘异常问题

这是Uproot旧版本的已知bug,升级到4.3.7及以上版本即可解决。

问题详情

用户使用ROOT 6.22/06创建带非均匀Bin的1-D直方图,经ROOT验证文件内的Bin边缘完全正确,但Uproot 4.0.0读取时错误生成了线性间隔的Bin边缘数值;而Uproot 4.3.7版本可正常读取到预期的非均匀Bin边缘。

ROOT测试代码(验证文件中Bin边缘正确)

{
  TFile *f = new TFile("uproot_test.root","new");
  Double_t binedges[6] = {0.1, 0.158489, 0.251189, 0.398107, 0.630957, 1};
  TH1D *h = new TH1D("hist","hist",5, binedges);
  h->Write();
  f->Close();

  // 重新打开文件验证Bin边缘
  TFile *f2 = new TFile("uproot_test.root");
  TH1D *h2 = (TH1D*)f2->Get("hist");
  TArrayD binEdges = *(h2->GetXaxis()->GetXbins());
  
  for (Int_t iX = 0; iX < binEdges.GetSize(); iX++) {
    std::cout << binEdges[iX] << std::endl;
  }
}

ROOT输出的正确Bin边缘

0.1
0.158489
0.251189
0.398107
0.630957
1

Uproot 4.0.0读取代码

import uproot

f = uproot.open('uproot_test.root')
h = f['hist']
print(h.axis().edges())

Uproot 4.0.0输出的错误Bin边缘

[0.1  0.28 0.46 0.64 0.82 1.  ]

结论

该问题是Uproot 4.0.0版本的兼容性bug,并非配置项问题。无需修改代码,只需将Uproot升级至4.3.7及以上版本,即可正确读取非均匀Bin的直方图边缘。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 11:00:56