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

Re: array manipulation problem



"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              |
|_________________________________________________________________|