Hello,
I thought I had read somewhere that the values in a numpy contiguous array are stored
column-wise (moving down from the upper left to the lower left first) like C as
opposed to row-wise (moving right from the upper left to the upper right first).
However, when I write a simply Pyrex function to access the data pointer and print it
out, it seems to go across the row. Is this correct? I am using numpy 0.9.3 and
Python 2.3 on Linux. This also occurs for Numeric. I post the code below, with the
sample output.
thanks,
bb
--
-----------------
bblais@bryant.edu
http://web.bryant.edu/~bblais
#test_numpy.pyx:
cdef extern from "numpy/arrayobject.h":
struct PyArray_Descr:
int type_num, elsize
char type
ctypedef class numpy.ArrayType [object PyArrayObject]:
cdef char *data
cdef int nd
cdef int *dimensions, *strides
cdef object base
cdef PyArray_Descr *descr
cdef int flags
def test_numpy(ArrayType x):
cdef int i
cdef double *data
cdef int length
data=
execfile('testit.py') [[ 1. 2. 3.] [ 4. 5. 6.] [ 7. 8. 9.] [ 10. 11. 12.]] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0
A Dimarts 28 Març 2006 15:59, Brian Blais va escriure:
Hello,
I thought I had read somewhere that the values in a numpy contiguous array are stored column-wise (moving down from the upper left to the lower left first) like C as opposed to row-wise (moving right from the upper left to the upper right first). However, when I write a simply Pyrex function to access the data pointer and print it out, it seems to go across the row. Is this correct?
Nope. C arrangement of values is row-wise and Fortran is column-wise. You are seeing row-wise ordering, so everything behaves as it should. Cheers, --
0,0< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data "-"
Francesc Altet wrote:
Nope. C arrangement of values is row-wise and Fortran is column-wise. You are seeing row-wise ordering, so everything behaves as it should.
interesting. I am coming from Matlab, where things are definitely column-wise organized. I always assumed this was the C standard, but now that I think of it the C double array [][] is row-wise. thanks, bb -- ----------------- bblais@bryant.edu http://web.bryant.edu/~bblais
Hi Brian,
On 3/28/06, Brian Blais
Francesc Altet wrote:
Nope. C arrangement of values is row-wise and Fortran is column-wise. You are seeing row-wise ordering, so everything behaves as it should.
interesting. I am coming from Matlab, where things are definitely column-wise organized. I always assumed this was the C standard, but now that I think of it the C double array [][] is row-wise.
Matlab was originally written in Fortran by Cleve Moler as an easy to use interface to LINPACK and EISPACK. If you google around you can probably find the original free Fortran version out on the net somewhere. Matlab was rewritten in C when John Little and Cleve Moler founded MathWorks but I imagine the new version still called many Fortran subroutines for the heavy lifting . You can find many other Fortran traces in Matlab. For instance, Matlab array indices start at 1 in the traditional Fortran way. On a side note, I believe that John Little's parents moved into the house that my family built in Lincoln, MA. Chuck
participants (3)
-
Brian Blais
-
Charles R Harris
-
Francesc Altet