On 2/15/07, Geoffrey Zhu <[EMAIL PROTECTED]> wrote:

I am really new to numpy but I just found that v[2:4] means selecting
v[2] and v[3]. V[4] is not included! This is quite different from the
conventions of matlab and R.


Yes, it is the Python slicing convention and rather similar to for loops in
C where

for(i = 0; i < N; i++)

is a common construction. It is an consequence of zero based indexing.
Matlab started in Fortran and uses the conventions of the Fortran do loop,
which no doubt makes sense for arrays whose base index is 1. Slicing in
NumPy, and now Python, also includes a step, so you can write a[0:n:2] to
reference all the elements with even indices.

Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to