I'm fairly new to C++ and struggling with pybind. I simply can't figure out how to convince pybind to convert a 2D vector from C++ to a python-readable format.
That's the code I have in mind:
py::array_t<float> to_matrix(std::vector<std::vector<float>> &vals)
{
int N = vals.size();
int M = 6;
py::array_t<float>({N, M}) arr;
for (int i = 0; (i < N); i++)
{
for (int j = 0; (j < M); j++)
{
arr[i][j] = vals[i][j];
};
};
return arr;
};
The input from C++ is a vector of vectors with N rows and 6 columns, simply a very long list of data points. Ideally I would like to have the output as a numpy array, but any python datastructure is fine (e.g., list of lists).
The documentation makes it sound so easy, but I can't figure it out. What am I doing wrong?
Thanks for any help in advance.