[Numpy-discussion] Some help on matlab to numpy translation

Fabrice Silva silva at lma.cnrs-mrs.fr
Sat Mar 13 12:20:55 EST 2010


> > As ux 's shape is (1,lx,ly), ux(:,1,col) is equal to ux(1,1,col) which
> > is a vector with the elements [ux(1,1,2), ... ux(1,1,ly-1)].
> > Using ":" juste after the reshape seems a lit bit silly...
> 
> Except that python uses 0-based indexing and does not include the last
> number in a slice, while Matlab uses 1-based indexing and includes the
> last number, so really:
>     ux(:,1,col)
> becomes:
>     ux(0, 0, col) # or ux(:, 0, col)
> 
> And if col is
>     col = [2:(ly-1)]
> This needs to be:
>     col = np.arange([1, ly - 1)

You are right about the 0 or 1 based indexing argument, but I was
speaking matlab language as visible in the symbols used for indexing
( () and not [] )... :)

-- 
Fabrice Silva
LMA UPR CNRS 7051




More information about the NumPy-Discussion mailing list