[Numpy-discussion] C vs. Fortran order -- misleading documentation?
Friedrich Romstedt
friedrichromstedt@gmail....
Tue Jun 8 17:49:56 CDT 2010
2010/6/8 Anne Archibald <aarchiba@physics.mcgill.ca>:
> Numpy arrays can have any configuration of memory strides, including
> some that are zero; C and Fortran contiguous arrays are simply those
> that have special arrangements of the strides. The actual stride
> values is normally almost irrelevant to python code.
First, I don't see the point why this text made it's way to this doc
page at all - it's all abstract Python numpy indexing on that page as
far as I can see - I don't know why a beginner should worry about
strides and how the linear memory is actually organised - from my
point of view I never did that.
To resolve the problem, and to avoid the confusion about the "fast"
and "slow", why not using directly the concept of strides as Anne
pointed out. Simply saying that:
When an array is indiced with indices (i1, i2, i3, ... in) and the
array has strides (s1, s2, s3, ..., sn), the memory location addressed
is:
i1 * s1 + i2 * s2 + ... + in * sn
relative to the base point (and up to dtype). I hope I'm not wrong here.
For C order,
s1 >= s2 >= ... >= sn = 1 ,
for fortran order the other way round.
Friedrich
In fact it holds:
s(k-1) = sk * Nk for C order,
s(k+1) = sk * Nk for fortran order,
where Nk is the length of dimension k.
If I'm not mistaken, it's late at night.
More information about the NumPy-Discussion
mailing list