[Numpy-discussion] C-API: How is data filling done in PyArray_SimpleNewFromData ?
Travis Oliphant
oliphant@enthought....
Tue Oct 27 14:54:53 CDT 2009
On Oct 27, 2009, at 7:43 AM, Raspaud Martin wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello,
>
> I’m using numpy v1.2.0, and I have the following codes that provide
> different results :
>
> - ---------------------
> cal = (PyArrayObject *)PyArray_SimpleNew(2,dims,NPY_FLOAT);
> for(i=0;i<dims[0];i++)
> for(j=0;j<dims[1];j++)
> {
> *((npy_float *)PyArray_GETPTR2(cal,i,j))=(npy_float)in[i][j];
> }
> - ---------------------
> and
> - ---------------------
> cal = (PyArrayObject *)PyArray_SimpleNewFromData(2,dims,NPY_FLOAT,in);
> - ---------------------
>
> As you probably guessed, "in" is a 2D array of floats of dimensions
> "dims".
>
> My questions are thus:
> - - Why do the two methods provide different results ?
> - - How do I get the second to behave like the first ?
>
In the second case, "in" should be a pointer to a place in memory with
space for dims[0]*dims[1] floats. In particular, it should not be a
2-d array of floats.
FromData expects to get a single pointer to float (not a 2D array).
I can't think of a way to get the second case to work other than have
"in" be a 1-D array.
-Travis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091027/fa6a6570/attachment.html
More information about the NumPy-Discussion
mailing list