1
이것은 간단한 질문이지만 초보자로 파악하지 못했습니다.파이썬 C- 확장에 전달 된 numpy 배열 요소를 변경하는 방법은 무엇입니까?
나는 다음과 같은 파이썬 C-확장 파일이 NumPy와 배열을 사용했다 : 나는 다음과 같은 호출이 "1"로 요소 clmn 배열을 수정하는 데 실패 발견 공유 라이브러리로 컴파일 한 후
#include <cmath>
#include <Python.h>
#include <iostream>
#include "numpy/arrayobject.h"
using namespace std;
PyObject *func_calc(PyObject *self, PyObject *args)
{
PyObject * PO_clmn;
PyArrayObject * py_clmn;
if (!PyArg_ParseTuple(args, "O", &PO_clmn))
return NULL;
py_clmn = (PyArrayObject*)PyArray_ContiguousFromObject(PO_clmn,PyArray_DOUBLE,1,1);
double *clmn = (double*)(py_clmn->data);
int i;
int N = py_clmn->dimensions[0];
int flag_threadholds[N_threadholds];
for (i=0; i<N; i++)
{
clmn[i]=1;
}
return Py_None;
}
static PyMethodDef exampleMethods[] =
{
{ "calc", func_calc, METH_VARARGS },
{ NULL, NULL }
} ;
PyMODINIT_FUNC initcalc()
{
import_array();
Py_InitModule("calc", exampleMethods);
}
을 :
import numpy
from calc import calc
clmn=numpy.zeros(10)
calc(clmn)
print clmn #[0,0...
미리 감사드립니다.