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

Re: array manipulation problem



"Martin B. Schmidt" wrote:

> Hi,
>
> Given:
>
>   n=500
>   a=FltArr(n,n,n)
>
> How can I assign
>   a[i,j,k] = i^2+j^2+k^2   for all i,j,k (i,j,k=0,1,2,..,n-1)
> without using any loop?
>
> Any idea?
>
>         Martin

n=500

i = REBIN(REFORM(FINDGEN(n),n,1,1),n,n,n)^2 ; x^2

a = i +  $                                  ; x^2

    TRANSPOSE(i,[1,0,2]) + $                ; y^2

    TRANSPOSE(i,[0,2,1])                    ; z^2

should work if you have enough memory( I only tried n=5, though, since
this allocates two large arrays, not counting temporary allocations)

--
Benno Puetz
Kernspintomographie
Max-Planck-Institut f. Psychiatrie            Tel.: +49-89-30622-413
Kraepelinstr. 10                              Fax : +49-89-30622-520
80804 Muenchen, Germany