Re: Applying scalar functions to arrays [message #10431] |
Fri, 05 December 1997 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Niels V�ver Petersen (vaever@mi.aau.dk) writes:
> How can you apply an IDL scalar function to each element in an
> array, without using for loops?
>
> Suppose we have the following array:
>
> IDL> a=[0.05,0.01,0.001]
>
> Calculating cosine is easy!
> IDL> print,cos(a)
> 0.998750 0.999950 1.00000
>
> But how about chi-square quantiles...?
> IDL> print,chisqr_cvf(a,17)
> % Compiled module: CHISQR_CVF.
> % Expression must be a scalar in this context: <BYTE Array[3]>.
In this particular case, it is a matter of the author of
CHISQR_CVF not realizing that people might want to obtain
a vector of values. So the code wasn't written to support
it. You could add that modification yourself, if you like,
by modifying the CHISQR_CVF source code in your lib directory.
Without modifying the code yourself, I am afraid you are
stuck with a loop. I speak with some experience when I say
that it is not always easy to anticipate what users are going
to try to do with your code. :-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|