Cython numpy array shape, tuples

I am using idiom

size_x, size_y, size_z = some_array.shape 

quite often when working with numpy arrays. The same does not seem to work in Cython when the array in question has a type, e.g.

  def someFunc(np.ndarray[np.float32_t, ndim=2] arr): sx, sy = arr.shape 

we get a compilation error like

  Cannot convert 'npy_intp *' to Python object 

which may be due to the fact that the "form" is converted to a C array (for faster access), so it is no longer a tuple.

Can this tuple be retrieved somehow even in Keaton? (Or should I just stick to sx, sy = arr.shape[0], arr.shape[1] ?)

+6
source share
1 answer

I believe that you are right that the direct way to deal with this is something like:

 cdef int sx, sy sx = arr.shape[0] sy = arr.shape[1] 

I don't know any other way to do this, and this is the convention that I use in my own code.

+4
source

All Articles