在C++ pybind11包装器中:
.def("calcSomething",
[](py::array_t<double> const & arr1,
py::array_t<double> const & arr2)
{
// do calculation
}
)在python中:
example.calcSomething(
arr1=np.full((10, 2), 20, dtype='float64'),
arr2=np.full((10, 2), 100, dtype='float64')
)我收到了一条错误信息:
ValueError: array has incorrect number of dimensions: 2; expected 1那么,如何将2d或nd数组传递给pybind11呢?
发布于 2022-03-09 14:22:02
在pybind11 array_t中是一个n维数组,就像numpy数组一样。
因此,对维数没有任何限制。
错误消息可能来自其他地方。不是来自pybind11。
至少,您显示的代码不应导致此行为。
https://stackoverflow.com/questions/71409168
复制相似问题