MathGroup Archive 1999

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

Search the Archive

Re: Combining Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16755] Re: [mg16722] Combining Lists
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Wed, 24 Mar 1999 02:24:00 -0500
  • Organization: debis Systemhaus
  • References: <199903230333.WAA07333@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear John

JOHN C ERB schrieb:
> 
> I have a set of x & y data points in one list;
> 
> xydata={{x1,y1},{x2,y2},{x3,y3},{x4,y4}};
> 
> and a corresponding set of z data points in another list:
> 
> zdata={z1,z2,z3,z4};
> 
> I wish to combine them into one list of {x,y,z} data points,
> which I can do by:
> 
> {temp1,temp2}=Transpose[xydata];
> xyzdata=Transpose[{temp1,temp2,zdata}]
> 
> which gives the desired result:
> 
> {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4}}
> 
> QUESTION:  Is there a more efficient way of doing this?
> 
Most probably not!

This *is* a very efficient method to do this. Look at the timing:

In[1]:= xyData=Array[{x[#],x[#]}&,50000];//Timing
Out[1]= {3.215 Second,Null}

In[2]:= zData=Array[z,50000];//Timing
Out[2]= {1.142 Second,Null}

In[3]:= rData=Transpose[Append[Transpose[xyData],zData]];//Timing
Out[3]= {1.161 Second,Null}
         ^^^^^^^^^^^^

I only found one close contender:

In[4]:= sData=MapThread[Append,{xyData, zData}];//Timing
Out[4]= {1.762 Second,Null}
         ^^^^^^^^^^^^
finally look at:

In[5]:= rData[[44444]]
Out[5]= {x[44444],x[44444],z[44444]}

In[6]:= sData[[44444]]
Out[6]= {x[44444],x[44444],z[44444]}

so both did it easily for 50000 Elements!

Regards, Hartmut



  • Prev by Date: Problems with meshs & non-Cartesian axes in 3D spaces.
  • Next by Date: Re: Commutators and Operator Powers in Mathematica
  • Previous by thread: Combining Lists
  • Next by thread: Re: Combining Lists