Re: array manipulation problem [message #20365] |
Wed, 07 June 2000 00:00 |
Benno Puetz
Messages: 16 Registered: March 2000
|
Junior Member |
|
|
Comparing Paul's solution to mine I found a typo in my previous post:
> 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 read [2,1,0]
--
Benno Puetz
Kernspintomographie
Max-Planck-Institut f. Psychiatrie Tel.: +49-89-30622-413
Kraepelinstr. 10 Fax : +49-89-30622-520
80804 Muenchen, Germany
|
|
|
Re: array manipulation problem [message #20368 is a reply to message #20365] |
Wed, 07 June 2000 00:00  |
Paul Hick
Messages: 9 Registered: November 1999
|
Junior Member |
|
|
"Martin B. Schmidt" wrote:
> 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?
one = replicate(1.0, n)
index = findgen(n)^2
a = reform( reform( index#one, n*n)#one + reform( one#index, n*n)#one
+ reform( one#one, n*n)#index ,n,n,n)
Not particularly pretty, but it should work.
Cheers,
Paul
--
____________________________________________________________ _____
| Paul Hick (pphick@ucsd.edu) |
| Office : SERF Rm. 302 Smail : UCSD/CASS/0424 |
| Phone : (858) 534-8965 9500 Gilman Drive |
| Fax : (858) 534-0177 La Jolla CA 92093-0424 |
| WWW : http://casswww.ucsd.edu/personal/Plh.html |
|___________________________________________________________ ______|
|
|
|
Re: array manipulation problem [message #20369 is a reply to message #20365] |
Wed, 07 June 2000 00:00  |
Benno Puetz
Messages: 16 Registered: March 2000
|
Junior Member |
|
|
"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
|
|
|