我在将 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,但不能使用对象类型。
你有什么想法吗?
最佳答案
由于您正在使用 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))
关于python - 将 C++ 类指针的向量发送到 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665049/