1

我在将 std 向量传递给 python 时遇到问题。

   std::vector<TMVA::Interval*> parameterRanges;
   parameterRanges.push_back(new TMVA::Interval(-10,10)); 
   parameterRanges.push_back(new TMVA::Interval(0.1,10)); 
   parameterRanges.push_back(new TMVA::Interval(0,2000));

我必须在 python 中做到这一点。不幸的是,我无法更改 Interval C++ 类。我可以在 python 中使用 std.vector,但只能使用 std.vector('double') 或 int,但不能使用对象类型。

你有什么主意吗?

4

1 回答 1

2

当您使用 TMVA 时,我假设您也有 ROOT。还有一个用于 pyroot 的 ROOT std::vector 包装器。它的用法如下:

import ROOT
VectorOfIntervalPointer = ROOT.std.vector('TMVA::Interval*')
# this is only a constructor, not an instance!

instance = VectorOfIntervalPointer()
from ROOT import TMVA.Interval
instance.push_back(TMVA.Interval(-10,10))
于 2016-04-05T13:44:12.513 回答