Re: programming comptition II
- To: mathgroup at smc.vnet.net
- Subject: [mg5047] Re: programming comptition II
- From: rhall2 at umbc.edu (hall robert)
- Date: Wed, 23 Oct 1996 01:38:10 -0400
- Organization: University of Maryland, Baltimore County
- Sender: owner-wri-mathgroup at wolfram.com
In article <54f397$74f at dragonfly.wolfram.com>, Xah Lee <xah at best.com> wrote: >Problem Two: Pairing of Nodes. >Given two list of the same Dimensions, how to combine the list so that >the end nodes of the new list pair the end nodes of given lists. Example >and solution: > >Clear[li1, li2] > >li1 = Array[f, {2,3,4}] >li2 = Array[g, {2,3,4}] > >Transpose[ {li1, li2}, >RotateRight@ Range@ Length@ Dimensions@ {li1, li2} >] Mathematica has built-in functions for dealing with multiple lists. MapThread[List, {li1, li2}, Depth[li1] -2] Alternately, you can get around the fact that List[] isn't listable with ListableFunction[li1, li2] /. ListableFunction -> List For example li1 + li2 /. Plus -> List This won't work with numbers; the function will be evaluated at the number pairs and each pair will be replaced by a single value. -- Bob Hall | "Know thyself? Absurd direction! rhall2 at gl.umbc.edu | Bubbles bear no introspection." -Khushhal Khan Khatak