我如何复制现有的PyArrayObject?
我已阅读此链接http://docs.scipy.org/doc/numpy/reference/c-api.array.html#creating-arrays
的文档我也读过这些解释: numpy array C api
PyArray_SimpleNewFromData example
我尝试使用PyArray_CopyInto和PyArray_CopyAnyInto,结果相同(错误)。
这是我的代码:
void from_list(PyObject*i_list) {
int x=1;
temp = retrieve(PyList_GetItem(i_list, x)); //list have 3 elements of type PyArrayObject*
}
void retrieve(PyArrayObject* slice) {
PyArrayObject*temp = CopyArray(slice);
}
PyArrayObject*CopyArray(PyArrayObject*obj) {
PyArrayObject*ret;
int nd = obj->nd;
int type_num = obj->descr->type_num;
unsigned char*data;
npy_intp dims[2];
dims[0] = obj->dimensions[0];
dims[1] = obj->dimensions[1];
data = malloc(dims[0]*dims[1] + 100);
memcpy( data, (unsigned char*)obj->data, dims[0]*dims[1] );
printf("\n ready to do \n");
ret = PyArray_SimpleNewFromData(nd, dims, NPY_CHAR, (void*)data); //python interpreter crashes
printf("\n ready to return \n");
return ret;
}
我做错了什么?另外,请你给我一个链接到PyArraySomething类型的所有函数的实现。
谢谢。