MathGroup Archive 1998

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

Search the Archive

Re: How: {{a,b},{1,2,3}} --> {{a,1},{b,2},{a,3}} ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14310] Re: How: {{a,b},{1,2,3}} --> {{a,1},{b,2},{a,3}} ?
  • From: Hans Staugaard <hans.staugaard at get2net.dk>
  • Date: Tue, 13 Oct 1998 01:21:25 -0400
  • Organization: Tele2 Internet Kunde
  • References: <6vf5es$dha@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Michael Kubovy wrote:
> 
> How do I get from {{a,b},{1,2,3}} to {{a,1},{b,2},{a,3}} ?
> 
> Thanks,
> |\  /|  / Michael Kubovy, Professor of Psychology, Dept of Psychology |
> \/ | /  Univ of Virginia, Gilmer Hall, Charlottesville, VA 22903-2477 |
> |/\  office (B011): 804-982-4729, lab (B019): -4751, fax: -4766  |    |
> \ HTTP://www.virginia.edu/~mklab/

I am not sure what you mean, but here is my intepretation of the
question:
Given a list containing list, form `mathcing' tuples, if a list runs
out,
cycle from beginning.
First i define a function pad:

pad[v:{__},n_Integer]:=         
  Take[Flatten[Table[v,{Ceiling[n/Length[v]]}]],n] /; n>Length[v]
pad[v:{__},n_Integer]:=
  v /; n=Length[v]

and then

maketuples[m:{{__}..}]:=
  With[{n=Max[Length[#]&/@m]},Transpose[pad[#,n]&/@m]]

this function should do the job, and will also work on things like

{{a,b},{1,2,3},{A,B,C,D}} yielding {{a,1,A},{b,2,B},{a,3,C},{b,1,D}}

Hans


  • Prev by Date: Re: Optimization packages for Mathematica: do they exist?
  • Next by Date: Re: Solving simultaneous eqns
  • Previous by thread: Re: How: {{a,b},{1,2,3}} --> {{a,1},{b,2},{a,3}} ?
  • Next by thread: Re: 2D histogram of x,y values