我正在尝试从cpp调用一些np功能。我已经创建了数组,并且正在尝试创建pyArray:
const int SIZE_X = 1000;
const int SIZE_Y = 9;
npy_intp dims[2]{SIZE_X, SIZE_Y};
const int ND = 2;
double* c_arr = reinterpret_cast<double*>(calloc(SIZE_X*SIZE_Y,sizeof(double)));
if (!c_arr) {
std::cout << "Out of memory." << std::endl;
}
for (int i = 0; i < SIZE_X; i++)
for (int j = 0; j < SIZE_Y; j++)
c_arr[i*SIZE_Y+j] = something;
//Convert it to a NumPy array.
PyObject *pArray = PyArray_SimpleNewFromData(
ND, dims, NPY_DOUBLE, reinterpret_cast<void*>(c_arr));
我也尝试过使用new。我得到的错误是:
unknown location:0: fatal error: in "basic": memory access violation at address: 0x00000010: no mapping at fault address
我尝试了一些类似import_array()的操作,但没有帮助。我看不到我想念的东西吗?