zero values in the output of PyArray_AsCArray(

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

zero values in the output of PyArray_AsCArray(

Boukhdhir Amal

 I am trying to access an array as a C-Type using the function 'PyArray_AsCArray'
The problem is that I am getting many 0 values in the resulting C- array. Some of the indexed
values are correct.

This is my code: 

static PyObject* cos_func_np(PyObject* self, PyObject* args)
        PyObject *in_array_object;
        PyObject *out_array;  
        int** segs_2d_array;
        /* Parse single numpy array argument*/
        if (! PyArg_ParseTuple(args, "O", &in_array_object))
            return NULL;
        int typenum = NPY_INT64;
        PyArray_Descr *descr;
        descr = PyArray_DescrFromType(typenum);                             
        npy_intp dims[2];                      
        PyArray_AsCArray(&in_array_object, (void**) &segs_2d_array, dims, 2, descr);                

        printf("\n-segs_2d_array: %d --\n", segs_2d_array[1][5]);                         
        //return Py_BuildValue("O", in_array_object);

For example:
segs_2d_array[0][0]  and segs_2d_array[1][2] outputs the correct values, however, segs_2d_array[1][3] and segs_2d_array[1][5] are equal to zero.

What is wrong with this code please ?

NumPy-Discussion mailing list
[hidden email]