You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy as np
cimport numpy as np
def boolFunc(np.ndarray[np.npy_bool, ndim=1] npdata):
return npdata
if you try to import and use it in python code:
from boolFunc import boolFunc
import numpy as np
# generate random boolArr
arr = np.random.randint(0,2, size=3, dtype=int)
boolArr = np.array(arr, dtype=bool)
# test cython function
boolFunc(boolArr)
you always get a particular ValueError:
ValueError: Does not understand character buffer dtype format string ('?')
This seems like it should work as is. In fact, this does work for other numpy types (eg npy_int, npy_double, etc). On the other hand, adding cast=True to the signature of boolFunc:
Here's a potential bug that I came across when answering a question on Stack Overflow.
Given a
boolFunc.pyx
file that looks like this:if you try to import and use it in python code:
you always get a particular
ValueError
:This seems like it should work as is. In fact, this does work for other
numpy
types (egnpy_int
,npy_double
, etc). On the other hand, addingcast=True
to the signature ofboolFunc
:fixes the error, but casting shouldn't be necessary here since we're explicitly passing in a
bool
typendarray
.The text was updated successfully, but these errors were encountered: