comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to apply a function to an array?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to apply a function to an array? [message #43998] Fri, 13 May 2005 01:37 Go to next message
W. Eremeev is currently offline  W. Eremeev
Messages: 3
Registered: February 2005
Junior Member
Suppose, I have a function with one scalar argument, returning a scalar
and an array of values.
I want to get another array with the same dimensions, containing
results of application of my function to the values in the first array.

R (www.r-project.org) has such functions (apply, lapply, sapply).
They take vectors or matrices and functions as arguments and return
arrays.

What about IDL?
Re: How to apply a function to an array? [message #44096 is a reply to message #43998] Fri, 13 May 2005 02:25 Go to previous message
Timm Weitkamp is currently offline  Timm Weitkamp
Messages: 66
Registered: August 2002
Member
Today at 11:05, Antonio Santiago wrote:

> W. Eremeev wrote:
>> Suppose, I have a function with one scalar argument, returning a scalar
>> and an array of values.
>> I want to get another array with the same dimensions, containing
>> results of application of my function to the values in the first array.
>>
>> R (www.r-project.org) has such functions (apply, lapply, sapply).
>> They take vectors or matrices and functions as arguments and return
>> arrays.
>>
>> What about IDL?
>>
> R is a functional programming language whereas IDL not. This means the
> working philosophy is pretty diferent.
>
> Sorry :(, but I dont know if there is a function or procedure in IDL
> that executes an specified function over a set of data. Perhaps you must
> think in terms of loops.

That said, any IDL function that returns a scalar expression for a single
scalar argument should (and usually does) also accept an array as the
argument, and return an array of the same dimensions. (Which eliminates
the need for an "apply" function.)

Example: the SIN function.

IDL> a = !pi/4
IDL> print, sin(a)
0.707107

IDL> b = [0, !pi/4, !pi/2]
IDL> print, sin(b)
0.00000 0.707107 1.00000

IDL> c = findgen(2,3,4)
IDL> help, sin(c)
<Expression> FLOAT = Array[2, 3, 4]

The situation is different for functions that reduce the dimensions of the
input array (such as MAX or TOTAL). Some of these functions (the number is
growing with every release of IDL) allow the user to specify a specific
dimension of the input array to which the function should be applied. For
those functions that don't, it is useful to have a look at Craig
Markwardt's CMAPPLY routine.

Cheers,
Timm

--
Timm Weitkamp <http://people.web.psi.ch/weitkamp>
Re: How to apply a function to an array? [message #44097 is a reply to message #43998] Fri, 13 May 2005 02:05 Go to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
W. Eremeev wrote:
> Suppose, I have a function with one scalar argument, returning a scalar
> and an array of values.
> I want to get another array with the same dimensions, containing
> results of application of my function to the values in the first array.
>
> R (www.r-project.org) has such functions (apply, lapply, sapply).
> They take vectors or matrices and functions as arguments and return
> arrays.
>
> What about IDL?
>
R is a functional programming language whereas IDL not. This means the
working philosophy is pretty diferent.

Sorry :(, but I dont know if there is a function or procedure in IDL
that executes an specified function over a set of data. Perhaps you must
think in terms of loops.

--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDLitComponent - Introspection
Next Topic: Re: problem with save

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:52:35 PDT 2025

Total time taken to generate the page: 0.00720 seconds