[Date Index]
[Thread Index]
[Author Index]
Re: From list to list of arguments
*To*: mathgroup at smc.vnet.net
*Subject*: [mg113301] Re: From list to list of arguments
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Sat, 23 Oct 2010 07:03:37 -0400 (EDT)
On 10/22/10 at 1:36 AM, sam.takoy at yahoo.com (Sam Takoy) wrote:
>Suppose I have a list of arrays, say g = {a, b, c} where a, b, and c
>are arrays, and I would like to calculate
>Outer[Times, a, b, c]
>how do I do it?
Perhaps
Fold[Outer[Times, #1, #2] &, a, {b, c}]
It is unclear to me what result you are looking for.
>I tried
>Apply[Outer[Times,#]&, g], as in Apply[Outer[Times, #] &, {{1},
>{1}}], but that does not yield the right answer. So the question is:
>how does one convert a list {a, b, c} into arguments to a function
>of variable number of arguments?
Use Sequence. For example:
In[1]:= f[x_, y_] := x y
In[4]:= testList = {2, 4};
f[Sequence @@ testList]
Out[5]= 8
of course for this toy example, f@@testList would obviously do
the same thing.
>An auxiliary question: within the function f[x__] := ... what kind
>of object is x? It's not a list, but what is it?
It is a sequence of one or more arbitrary things. Look up
Sequence in the Documentation Center
Prev by Date:
**Re: Two questions related to Arrays**
Next by Date:
**Re: Two questions related to Arrays**
Previous by thread:
**From list to list of arguments**
Next by thread:
**Re: From list to list of arguments**
| |