[Date Index]
[Thread Index]
[Author Index]
Re: Problems with Outer
*Subject*: [mg2876] Re: Problems with Outer
*From*: villegas (Robert Villegas)
*Date*: 4 Jan 1996 04:14:05 -0600
*Approved*: usenet@wri.com
*Distribution*: local
*Newsgroups*: wri.mathgroup
*Organization*: Wolfram Research, Inc.
*Sender*: mj at wri.com
In article <4caqcr$fc at dragonfly.wri.com> "Ross Moore
<ross at zeus.mpce.mq.edu.au>" <ross at zeus.mpce.mq.edu.au> writes:
> I want to create the outer product of some lists, whose
> elements themselves may be lists.
> But when the heads of the elements are List , the result
> is quite different...
>
> (Zeus2.2.2) In[3]:= Outer[{#1,#2}&
> , {List[a,a,a],List[b,b,b]}
> , {List[c,c,c],List[d,d,d]}]//MatrixForm
>
> (Zeus2.2.2) Out[3]//MatrixForm=
> a a a a a a a a a
> c c c c c c c c c
> a a a a a a a a a
> d d d d d d d d d
>
> b b b b b b b b b
> c c c c c c c c c
> b b b b b b b b b
> d d d d d d d d d
If you are using version 2.2, then Outer accepts one or more integers
after the lists specifying to what depth Outer should go in each of
the lists. In general,
Outer[f, list1, ..., listk, n1, ..., nk]
means treat list1 as having depth n1, . . . , listk as having depth nk.
We did not add this until version 2.2, which is why it did not appear in
the second edition of the book.
Applying this to your example:
In[5]:= Outer[f, {{a, a, a}, {b, b, b}}, {{c, c, c}, {d, d, d}}, 1, 1]
Out[5]= {{f[{a, a, a}, {c, c, c}], f[{a, a, a}, {d, d, d}]},
> {f[{b, b, b}, {c, c, c}], f[{b, b, b}, {d, d, d}]}}
In[6]:= MatrixForm[%]
Out[6]//MatrixForm= f[{a, a, a}, {c, c, c}] f[{a, a, a}, {d, d, d}]
f[{b, b, b}, {c, c, c}] f[{b, b, b}, {d, d, d}]
If you give just one depth specification, then it applies to all the
lists, not just the first, so be careful not to assume that the rest
will default to Infinity. In other words,
Outer[f, list1, ..., listk, n]
is equivalent to
Outer[f, list1, ..., listk, n, n, ..., n]
NOT to Outer[f, list1, ..., listk, n, Infinity, ..., Infinity]. Supply
extra Infinity arguments if you don't want a lone depth specification
to apply to all lists.
Robby
Prev by Date:
**Re: Problems with Outer**
Next by Date:
**Re: Should I get Matlab or Mathematica or ?**
Previous by thread:
**Re: Problems with Outer**
Next by thread:
**Re: Re: Problems with Outer**
| |