[SciPy-user] Fwd: interpolation question

John Travers jtravs at gmail.com
Wed Oct 24 12:00:08 EDT 2007


Hi Mike,

On 24/10/2007, Michael Hearne <mhearne at usgs.gov> wrote:
> John - I guess I have a different bias - in Matlab (and now numpy) I've
> always thought of rows being in the y direction, and columns as being in the
> x direction.  This explains my confusion with the x and y parameters.

> Is it uncommon to think of columns as being in the x direction, and rows in
> y?
>

I think we are just confusing each other. If you look at my bad ascii
art 2d-array below:

--------------------
| 0,0 | 0,1 | 0,2 |
--------------------
| 1,0 | 1,1 | 1,2 |
--------------------

My understanding is:
This is a 2 by 3 array. The first index runs from 0 to 1 inclusive.
This indexes the rows of the array. The second index runs from 0 to 2
inclusive and indexes the columns of the array. So 1,0 is the 2nd row,
1st column.  Now I regard x as the first index (because I think of it
as the first axis). Therefore x corresponds to the rows. So obviously
y is the second index and hence corresponds to the columns. I think
maybe out confusion comes from the fact that for a given column (or y
value) we index through it by row (or x value) and maybe you think of
this as each set of x's lies in a column?

The fortran bias comes from the fact that in fortran it is more
efficient to change the inner index (row or x) fastest. This agrees
with my idea of x corresponding to the first index (rows) as x is
often the fastest changing axis (though this is an arbitrary choice).

Anyway I think Matlab, numpy and Fortran all work like this in terms
of indexing.

But numpy (and Matlab?) is written in c and therefore it is usually
more efficient to change the second index fastest. I say usually as
numpy also supports storing arrays in fortran order, but users don't
normally need to worry about this. So I guess another source of
confusion is that if users want x to be the most efficiently indexed
axis, they should consider it to be represented by the second index
(or columns).

By the above interpretation I think my implementation of
RectBivariateSpline is consistent with the first index changing x. If
you think this is a bad choice or inconsistent with the rest of
scipy/numpy I'd like to hear.

I apologise if all this is too basic for you, I don't mean to insult!

Cheers,
John



More information about the SciPy-User mailing list