我需要读取一个根树,其中包含一个存储在结构中的2D数组,为此我想使用uproot。
例如:下面的代码片段在一个结构中创建了一个同时具有二维数组和二维数组的树。Uproot本身读取2D数组没有问题,但不知道如何在结构中解析它。
有没有办法告诉uproot如何解析这个结构?
Float_t x2[15][2]={{0}};
struct POINT{
Float_t x[15][2]={{0}};
Float_t y[15][2]={{0}};
};
POINT point;
TTree tree("T","ROOT tree with 2D array and 2D array in struct");
tree.Branch("point",&point,"x[15][2]:y[15][2]");
tree.Branch("x2",x2,"x2[15][2]/F");发布于 2020-06-23 01:52:52
虽然我无法在没有文件的情况下对此进行测试,但下面的代码应该允许您读取该数据结构:
import numpy as np
import uproot
dtype = np.dtype([("x", ">f4", (15, 2)), ("y", ">f4", (15, 2))])
interpretation = uproot.asdtype(dtype)
points_array = tree["point"].array(interpretation)这是一个问题,Uproot不能识别这种结构,尽管我可以想象为什么不能:这是一个特殊情况(固定大小的维度)的特殊情况(叶子列表)。如果您可以发布一个小的(< 1MB)示例文件作为一个根治GitHub问题,我将研究自动识别此interpretation的问题。
https://stackoverflow.com/questions/62519766
复制相似问题