[Numpy-discussion] Offset 2D arrays

Herbert L. Roitblat roitblat at hawaii.edu
Wed Sep 19 10:14:03 CDT 2001


Konrad's solution is MUCH more elegant.
HLR
----- Original Message -----
From: "Konrad Hinsen" <hinsen at cnrs-orleans.fr>
To: <roitblat at hawaii.edu>
Cc: <chrishbarker at home.net>; <romberg at fsl.noaa.gov>;
<numpy-discussion at lists.sourceforge.net>
Sent: Tuesday, September 18, 2001 10:05 PM
Subject: Re: [Numpy-discussion] Offset 2D arrays


> > This will work:
> > b=zeros ((3,3))
> > b[:2,:2] = b[:2,:2] + a[1:,1:]
> >
> > You need to know the size of a to use this scheme.
>
> How about this:
>
>    b = 0*a
>    b[:-1, :-1] = a[1:, 1:]
>
> Works for any shape and type of a.
>
> Konrad.
> --
> --------------------------------------------------------------------------
-----
> Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
> Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
> Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
> 45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
> France                                   | Nederlands/Francais
> --------------------------------------------------------------------------
-----
>





More information about the Numpy-discussion mailing list