[Cython] how to get a double** from np.ndarray[double, ndim=2]

Adrian Martínez Vargas adriangeologo at yahoo.es
Mon Sep 5 18:25:44 CEST 2011


Hi,

I would like to get a double** from a 2d numpy array in cython in order 
to call properly some function written in C++. Can some one to give a 
pure cython solution?

 From now I have a double* from the np.ndarray[double, ndim=2] .data. 
I'm getting the double array in C++ with:

     array2D_=new double* [nrows];
     for (int i=0; i<nrows; ++i)
     {
       array2D_[i]=ptr1D;
       ptr1D+=ncols;
     }

with that I'm responsible to delete the array from C++

//     delete [] this->array2D_[0];  // delete the memory pool
     delete [] this->array2D_;      // delete the row pointers

but this->array2D_[0];  is shared with the numpy array.

I think that it may be more elegant to get directly a double** from 
numpy and let to python the responsibility of managing the memory.


  Regards
Adrian Martínez Vargas


More information about the cython-devel mailing list