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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion