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.

Joel Vroom
  • 1,611
  • 1
  • 16
  • 30

1 Answers1

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.

seberg
  • 8,785
  • 2
  • 31
  • 30
  • 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? – user1700887 Sep 26 '12 at 17:23
  • 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. – seberg Sep 26 '12 at 18:57
  • 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. – user1700887 Sep 26 '12 at 20:02