MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Problems with Outer

In article <4caqcr$fc at> "Ross Moore   
<ross at>" <ross at> 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.



  • Prev by Date: Re: help with graphics command
  • Next by Date: Re: Problems with Outer
  • Previous by thread: Problems with Outer
  • Next by thread: Re: Problems with Outer