?Loading double and cdouble in an PyArrayObject?
How do I take data from a double array or a complex array as defined below and initialize a Numeric array and load it appropriately? struct complex { double real; double imag; } complex; complex cdata[100]; double *data[100]; PyArrayObject *array; /* code where cdata and data are loaded up is not included *. I think this is how I do it for doubles (correct me if I'm wrong). array = PyArray_FromDims(1, numData, PyArray_DOUBLE) for (i=0; i< 100; i++) { (double *)(array->data)[i] = data[i]; } How do I load the data in cdata into an PyArrayObject? Thanks, Norman Shelley
A Dimarts 07 Octubre 2003 17:58, Norman Shelley va escriure:
How do I take data from a double array or a complex array as defined below and initialize a Numeric array and load it appropriately?
struct complex { double real; double imag; } complex;
complex cdata[100]; double *data[100]; PyArrayObject *array;
By reading the manual (page 65), I guess the best would be something like: arr = PyArray_FromDimsAndData(1, 100, PyArray_CDOUBLE, cdata) Cheers, -- Francesc Alted
Francesc Alted wrote:
A Dimarts 07 Octubre 2003 17:58, Norman Shelley va escriure:
How do I take data from a double array or a complex array as defined below and initialize a Numeric array and load it appropriately?
struct complex { double real; double imag; } complex;
complex cdata[100]; double *data[100]; PyArrayObject *array;
By reading the manual (page 65), I guess the best would be something like:
arr = PyArray_FromDimsAndData(1, 100, PyArray_CDOUBLE, cdata)
If cdata is never to be freed, e.g. a Fortran COMMON block, then that is the case. I with to use PyArray_FromDims() and then load it up with data I am assuming this may work for doubles (?) aPyArrayObject = PyArray_FromDims(1, numData, PyArray_DOUBLE) for (i = 0; i < numData; i++) aPyArrayObject.data[i] = doubledata[i]; But then I wondered how to load for COMPLEX?
Cheers,
-- Francesc Alted
A Dimarts 07 Octubre 2003 18:24, Norman Shelley va escriure:
If cdata is never to be freed, e.g. a Fortran COMMON block, then that is the case. I with to use PyArray_FromDims() and then load it up with data
I am assuming this may work for doubles (?) aPyArrayObject = PyArray_FromDims(1, numData, PyArray_DOUBLE) for (i = 0; i < numData; i++) aPyArrayObject.data[i] = doubledata[i];
But then I wondered how to load for COMPLEX?
Perhaps something like: struct complex { double real; double imag; } complex; complex cdata[100]; double *data; PyArrayObject *array; array = PyArray_FromDims(1, numData, PyArray_CDOUBLE) data = array->data for (i = 0; i < numData; i++) { *data++ = cdata[i++]; *data++ = cdata[i]; } should work (but not tested here). CDOUBLE means double precision complex. Something similar would work for double precision: complex ddata[100]; double *data; PyArrayObject *array; array = PyArray_FromDims(1, numData, PyArray_DOUBLE) data = array->data for (i = 0; i < numData; i++) { *data++ = cdata[i]; } -- Francesc Alted
participants (2)
-
Francesc Alted
-
Norman Shelley