【问题标题】:Send vector of class C++ pointers to python将类 C++ 指针的向量发送到 python
【发布时间】:2015-04-24 06:15:58
【问题描述】:

我在将 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,但不能使用对象类型。

你有什么想法吗?

【问题讨论】:

  • 你能在 Python 中访问 TMVA::Interval 而不将其放入向量中吗?这将是您必须首先解决的问题。

标签: python class wrapper root-framework


【解决方案1】:

当您使用 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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    相关资源
    最近更新 更多