I would like to pass the following array of list of integers (i.e., it's not an two dimensional array) to the Cython method from python code.
Python Sample Code:
import numpy as np
import result
a = np.array([[1], [2,3]])
process_result(a)
The output of a is array([list([1]), list([2, 3])], dtype=object)
Cython Sample Code:
def process_result(int[:,:] a):
pass
The above code gives the following error:
ValueError: Buffer has wrong number of dimensions (expected 2, got 1)
I tried to pass a simple array instead of numpy I got the following error
a = [[1], [2,3]]
process_result(a)
TypeError: a bytes-like object is required, not 'list'
Kindly assist me how to pass the value of a into the Cython method process_result and whats the exact datatype needs to use to receive this value in Cython method.
a. Is that a 2d array, or 1d? Count the[]or look at its shape. If that's what you want to pass tocython, why are you using[:,:]instead of[:]? You may need more experience withnumpyin interpreted Python before moving on tocython.[]is not an issue, but whats the datatype that I need to use.def process_result( ??? [:] a):<void>[:]might work. cython.readthedocs.io/en/latest/src/userguide/….aitemsizeis 8, the items being pointers to the lists elsewhere in memory. Comparenp.frombuffer(a,'int64')withid(a[0]). So any 8 byte dtype should be acceptable.