【发布时间】:2021-06-08 00:35:08
【问题描述】:
我想将 numpy 数组传递给 c++,但是有一个已弃用的 numpy API,我不知道在哪里可以找到替代品。 当我构建我的 C++ 代码来制作库时,它会向我显示一条警告消息。
numpy\npy_1_7_deprecated_api.h(14):警告消息:使用已弃用的 NumPy API,使用 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 禁用它
使用不推荐使用的 API 有什么问题吗?如果我使用它,它只运行一次,然后退出我的程序,没有任何进一步的错误/警告消息(这个 cfunc 应该在我的导入 c 库的 python 代码的循环中运行多次。)。当然,如果我禁用了已弃用的 API,它只会告诉我它找不到该 API。
这是我的代码的一部分,用于接收 numpy 数组并将其转换为双数组以在 c++ 中处理它
#include <Python.h>
#include "numpy\ndarraytypes.h"
#include "numpy\ndarrayobject.h"
#include "numpy\arrayobject.h"
static PyObject* cfunc(PyObject* self, PyObject* args)
{
PyArrayObject* numpyarray;
double* carray;
if (!PyArg_ParseTuple(args, "O", &numpyarray))
{
return NULL;
}
carray = (double*)numpyarray->data; // When I build this code, it says 'data' is not a member of 'tagPyArrayObject'
如果您有任何想法,请告诉我。
非常感谢!
最好的祝愿, 耶苏
【问题讨论】:
标签: python c++ numpy numpy-ndarray