operating on 3-D arrays [message #8408] |
Fri, 07 March 1997 00:00  |
John Keck
Messages: 10 Registered: August 1996
|
Junior Member |
|
|
The IDL manual encourages avoiding FOR...NEXT loops by using the vaunted
matrix capabilities of IDL, so I have been trying to handle
three-dimensional arrays with these facilities.
I need to multiply three vectors to produce a three-dimensional array.
One would think that it would suffice to use the matrix multiplication
operator (#) as one does with a pair of vectors to get a two-dimensional
array. However with three vectors, IDL gives the error message
% Operands of matrix multiply have incompatible dimensions...
Anyone have a simple way to manipulate three (and higher) dimensional
arrays in IDL?
Thanks,
John Keck
|
|
|
Re: operating on 3-d arrays [message #8489 is a reply to message #8408] |
Mon, 10 March 1997 00:00  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
John Keck <jwk@phys.columbia.edu> writes:
> The IDL manual encourages avoiding FOR...NEXT loops by using the vaunted
> matrix capabilities of IDL, so I have been trying to handle
> three-dimensional arrays.
>
> I need to multiply three vectors to produce a three-dimensional array.
> One would think that it would suffice to use the matrix multiplication
> operator (#) as one does with a pair of vectors to get a two-dimensional
> array. However with three vectors, IDL gives the error message
>
> % Operands of matrix multiply have incompatible dimensions...
>
> Anyone have a simple way to manipulate three (and higher) dimensional
> arrays in IDL?
>
This might do what you want. Suppose you had three vectors, called A, B, and C
that you wanted to multiply together such that the result R had the property
R(i,j,k) = A(i) * B(j) * C(k)
You could then use the following commands:
R = A # B
R = R(*) # C
R = REFORM(R, N_ELEMENTS(A), N_ELEMENTS(B), N_ELEMENTS(C))
Bill Thompson
|
|
|