PyROOT and 3D vector


It seems that a 3D vector is not supported by PyROOT in the same way as 2D and 1D vectors are:

f = ROOT.vector("vector<vector<int>>")()
f+=np.arange(27, dtype=np.int32).reshape(3,3,3)

results in a segfault here, which finishes in:

TypeError                                 Traceback (most recent call last)
Cell In [2], line 2
      1 f = ROOT.vector("vector<vector<int>>")()
----> 2 f+=np.arange(27, dtype=np.int32).reshape(3,3,3)

File /opt/root-6.26.00-patches-git/lib/cppyy/, in Template.__call__.<locals>.iadd(self, ll)
     72 def iadd(self, ll):
     73     self.reserve(len(ll))
---> 74     for x in ll: self.push_back(x)
     75     return self

TypeError: none of the 2 overloaded methods succeeded. Full details:
  void std::vector<vector<vector<int> > >::push_back(vector<vector<int> >&& __x) =>
    TypeError: could not convert argument 1
  void std::vector<vector<vector<int> > >::push_back(const vector<vector<int> >& __x) =>
    TypeError: could not convert argument 1

I understand that it does not convert the interior of the numpy array to vector. Of course, I can make a loop and push_back each of the elements into the vector, but that will be very slow, as it is with Python loops. Is there a way to make it as fast as += and assign work for 1D and 2D vectors?

ROOT Version: 6.26.11
Platform: Not Provided
Compiler: Not Provided

Maybe @vpadulan can help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.