1

I have a dynamic 2 dimensional C array, for example an array that created by this code:

double **multiDyArr=(double**)malloc(sizeof(double*)*3);
multiDyArr[0]=(double*)malloc(sizeof(double)*3);
multiDyArr[1]=(double*)malloc(sizeof(double)*17);
multiDyArr[2]=(double*)malloc(sizeof(double)*11);

How can I create a PyArrayObject from this structure, specially how I can create a numpy array that hold 3 object(off course 3 is an example here) (each of them is an array) I searched a lot, but it seems I can't get how to do this in my life.

1 Answer 1

1

Numpy arrays are always a single block of memory, the closest python datatype to map this to is a python list, tuple or object array of arrays. Even if you had it all in one memory block that would not help as numpy arrays have to be regular.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks seberg. but I can create an array of objects using numpy, then I can assign an arbitrary array to each element of array(in python interpreter). what do you think of this? edit: Now I see you mention object array of arrays.probably you mean this. so how to create an array of objects array in numpy C api?
I guess thats what you wanted all along, sorry... Never really used the C-API, but I think you should be able to just create it normally using NPY_OBJECT as datatype after creating a PyObject* C-array, or create an empty NPY_OBJECT array and fill it.
no problem, I think to filling array, I need some pointer manipulation, and I'm almost beginner to C.couldn't figured it out myself, probably I stick to list.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.