我想在C++中使用一个类型为bool的numpy数组,方法是通过Cython传递它的指针.我已经知道如何使用uint8等其他数据类型.用布尔值以同样的方式做它不起作用.我能够编译,但在运行时有以下异常:
Traceback (most recent call last):
File "test.py", line 15, in <module>
c = r.count(b, 4)
File "rect.pyx", line 41, in rect.PyRectangle.count (rect.cpp:1865)
def count(self, np.ndarray[bool, ndim=1, mode="c"] array not None, int size):
ValueError: Does not understand character buffer dtype format string ('?')
Run Code Online (Sandbox Code Playgroud)
这是我的c ++方法:
void Rectangle::count(bool * array, int size)
{
for (int i = 0; i < size; i++){
std::cout << array[i] << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
Cython文件:
# distutils: language = c++
# distutils: sources = Rectangle.cpp
import …Run Code Online (Sandbox Code Playgroud)