Boukhdhir Amal
2017-02-07 22:40:46 UTC
Hi,Â
 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 indexedvalues 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 ?
 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 indexedvalues 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 ?