Re: Arrays with complex index ? [message #18276 is a reply to message #18128] |
Sat, 04 December 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Henrik E. Nilsen wrote:
> Annyone know if there's a way to reference a floating point array using a
> complex number?
>
> what I would like to do is something like:
>
> cnum=complex(5,5) & cnum2=complex(2,3) & fnum=10.7
> arr=fltarr(cnum)
> arr[cnum2]=fnum
>
> and not:
>
> arr=fltarr(5,5)
> arr[float(cnum),imaginary(cnum)]=fnum
>
> I suspect that this is not possible. Does anyone know how time
> consumining the 'float' and 'imaginary' commands are? (I'm using these
> statments at the core of a loop structure, and so any savings in time are
> important)
Regarding the use of a complex variable as an array subscript, here's what
the documentation says (Building IDL applications; Subscript Examples):
"Subscripts can be any type of vector or scalar expression. If a subscript
expression is not integer, a longword integer copy is made and used to
evaluate the subscript."
Thus the following statements are legal, but only the real part of the
complex number is used to form the subscript:
IDL> arr = indgen(10)
IDL> index = complex(1.0, 2.0)
IDL> help, long(index)
<Expression> LONG = 1
IDL> help, arr[index]
<Expression> INT = 1
The second example you gaev looks fine to me, e.g.
arr = fltarr(5,5)
arr[float(cnum),imaginary(cnum)] = fnum
I don't think there's any great time penalty incurred by using float() and
imaginary(). You'll gain much more speed by finding a way to express your
algorithm in array operations rather than loop operations.
Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
|
|
|