[Numpy-discussion] Re: Numpy-discussion digest, Vol 1 #50 - 2 msgs
Vanroose Wim
vanroose at ruca.ua.ac.be
Thu May 4 05:26:48 EDT 2000
Dear Travis Oliphant,
The pointer result->data is of type (char *). So I still have
to do a cast
data = (Py_complex *)result->data;
Best Wishes
Wim Vanroose
Travis Oliphant wrote:
> Yes, you can create the array, point a pointer to "result->data" and fill
> it in. Internally, when the array is created an equivalent malloc is
> performed.
>
> I've changed your code below to eliminate the unecessary copying.
> >
> >
> > static PyObject* matrix(PyObject *self, PyObject *args){
> > double x,y;
> > int size;
> > int M,n,m;
> > PyArrayObject *result;
> > int dimensions[2];
> > Py_complex *data;
> > Py_complex p;
> > if(!PyArg_ParseTuple(args,"idd",&M,&x,&y))
> > return NULL;
> > dimensions[0] = M;
> > dimensions[1] = M;
>
> > result = (PyArrayObject
> > *)PyArray_FromDims(2,dimensions,PyArray_CDOUBLE);
>
> > data = result->data;
> > for(n=0;n < M;n++){
> > for(m=0; m<M; m++){
> > p.real=x;
> > p.imag=y;
> > data[n*M+m] = p;
> > }
> > }
>
> > return PyArray_Return(result);
> > free(data);
> > }
> >
>
> Welcome to the wonderful world of NumPy.
>
> -Travis
More information about the NumPy-Discussion
mailing list