MathGroup Archive 1997

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

Search the Archive

Re: Re: Threading objects of unequal length

  • To: mathgroup at
  • Subject: [mg8243] Re: [mg8136] Re: [mg8112] Threading objects of unequal length
  • From: Allan Hayes <hay at>
  • Date: Thu, 21 Aug 1997 21:16:59 -0400
  • Sender: owner-wri-mathgroup at

Further to my previous posting, here's another, faster, way - ten  
times as fast:
(I use the name MapThreadRagged because function is more like  
MapThread than Thread)

MapThreadRagged[h_,d_] :=
	   	ml = Max[Length /@ d];
       		pd = Table[x,{ml}];
       		tb = Take[Join[#,pd],ml]&/@d;
       		mth = MapThread[h, tb];
       		DeleteCases[mth, x, {2}]


MapThreadRagged[h,{{a,b}, {c,d,e}, {f},{g}}]


MapThreadRagged[h,{{a,b}, {c,d,e}}]


Timings - comparison with Wouter's WollThread2 from previous posting 

{i, Max[Length/@args]}]

tst = Table[Range[Random[Integer,100]],{100}];

(mtr = MapThreadRagged[h,tst]);//Timing
	{0.5156 Second,Null}

(wt = WollThread2[h,tst]);//Timing

	{5.26479 Second,Null}

mtr == wt

Allan Hayes
hay at
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

  • Prev by Date: Mathematica Graphics
  • Next by Date: Re: AW: Saving graphics in Mma 3.0.1
  • Previous by thread: Re: Threading objects of unequal length
  • Next by thread: Re: Re: Threading objects of unequal length