Cython memoryviews

Stéfan van der Walt stefan at sun.ac.za
Thu Apr 18 10:07:54 EDT 2013


On Tue, Apr 16, 2013 at 5:45 AM, Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
>> cnp.ndarray[dtype=float, ndim=2] -> double[:, ::1]
>
> Can you explain this syntax to me? I'd understand double[:, :], but not sure
> I get double[:, ::1]. Are you indicating that the array should be
> interpreted in C order? Would double[::1, :] indicate a Fortran-order array?
> And is double[:, ::1, :] invalid? Finally, can you take any array as input
> and reinterpret as a one-dimensional array?

Yes, the ::1 indicates the contiguous dimension, and can only be used
in the first and last places.

I'm not sure I understand your last question correctly, but you can do:

def foo(x):
    cdef double[:] y = x.ravel()
    return y[0]

Stéfan



More information about the scikit-image mailing list