[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generally accessing the rest of the elements in an array



"tbowers" <tbowers@nrlssc.navy.mil> writes:

>How do I access the 2nd + dimensions of an array generally, without knowing
>the
>number of higher dims this array has. E.g. say a is a 3 column by
>n-dimensional
>aray, and n is unknown. Here, I'll define it as:

>a = indgen(3,2,4)

>I want the equivalent of (in this case):
>b = (a[0,*,*])^2 + (a[1,*,*])^2 + (a[2,*,*])^2

			(rest deleted)

You should be able to do something like the following:

    b = a[0,*,*,*,*,*,*,*]^2 + a[1,*,*,*,*,*,*,*]^2 + a[2,*,*,*,*,*,*,*]^2

even though A might not have so many dimensions.  With your above example, you
would then get

    IDL> help,b
    B               INT       = Array[1, 2, 4]

William Thompson