Python list to Cython Python list to Cython arrays arrays

Python list to Cython


You'll need to copy the contents of the list to an array explicitly. For example...

cimport cythonfrom libc.stdlib cimport malloc, free...def process(a, int len):    cdef int *my_ints    my_ints = <int *>malloc(len(a)*cython.sizeof(int))    if my_ints is NULL:        raise MemoryError()    for i in xrange(len(a)):        my_ints[i] = a[i]    with nogil:        #Once you convert all of your Python types to C types, then you can release the GIL and do the real work        ...        free(my_ints)    #convert back to python return type    return value