I have an np.ndarray that looks like this:
print(x)
[[1 3 None None None None]
[0 2 3 4 None None]
[1 5 4 None None None]
[1 6 0 4 None None]
[7 6 5 1 3 2]
[4 7 2 8 None None]
[7 4 3 None None None]
[4 6 8 5 None None]
[7 5 None None None None]]
I am supplying it to a cython function defined as follows:
cpdef y(int[:,::1] x):
...
This throws up the error: ValueError: Buffer dtype mismatch, expected 'int' but got Python object
This is probably happening because of the presence of Nones in the array, since modifying them to 0s removes the error. But the presence of None should not be posing a problem, as written here: Cython Extension Types
So, what is going on? Is there a quick solution to this?
a = np.array([1, None]),a.dtypeisobject, that's the problem,int[:,::1]expect an int buffer, but got an object bufferNone, whereas you have an array that is made up ofintandnon-int/Nonevalues, which is not valid.Nones to be integers? Or do I just have to convert theNones to someintvalue?