简体   繁体   English

PyArray_BOOL声明并使用C扩展中的Numpy布尔数组

[英]PyArray_BOOL declaration & working with Numpy array of bools in C extension

I have a NumPy array of bools in my code that I wish to write a C extension to. 我的代码中有一个NumPy布尔数组,希望将其编写为C扩展。 When I try to get a contiguous array in order to use in my C routine, I use: 当我尝试获取连续数组以便在C例程中使用时,我使用:

arr_mask = (PyArrayObject *)
    PyArray_ContiguousFromObject(mask, PyArray_BOOL, 2, 2);

But I get the compiler error that PyArray_BOOL is not declared. 但是我收到未声明PyArray_BOOL的编译器错误。

xor_masking.c:44:40: error: ‘PyArray_BOOL’ undeclared (first use in this function)

Why it is so? 为什么会这样呢? Is this type undeclared? 此类型未声明吗? If it is so, how can I introduce my array of bools to C? 如果是这样,如何将我的布尔数组引入C?

Thanks! 谢谢!

You need to use NPY_BOOL rather than PyArray_BOOL. 您需要使用NPY_BOOL而不是PyArray_BOOL。 Also, you will need to be using the numpy header rather than the numeric header if you are still using the numeric header like in one of your other questions. 另外,如果像其他问题之一一样仍在使用数字标头,则需要使用numpy标头而不是数字标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM