I have the following two lists (each containing over 500,000 elements). Here is a sample:
lis1 = { {1.86582, 1.70162, 1.25256}, {1.82707, 1.29901, 1.10659},
{1.76547, 1.21544, 1.09433}, {1.18306, 1.28322, 1.75524},
{1.12555, 1.98011, 1.53359}, {1.10584, 1.12299, 1.88411},
{1.83799, 1.5275, 1.76179}, {1.42352, 1.45163, 1.45318},
{1.63669, 1.78145, 1.60307}, {1.61749, 1.44287, 1.57405}
};
and
lis2 = {0.826095, 0.73286, 0.918137, 0.937434, 0.506525,
0.562795, 0.664915, 0.789321, 0.6559, 0.398447}
They both have equal Lengths. I want to combine both Lists to obtain a new list that looks like this
{ {1.86582, 1.70162, 1.25256, 0.826095},
{1.82707, 1.29901, 1.10659, 0.73286},
{1.76547, 1.21544, 1.09433, 0.918137},
{1.18306, 1.28322, 1.75524, 0.937434},
{1.12555, 1.98011, 1.53359, 0.506525},
{1.10584,1.12299, 1.88411, 0.562795},
{1.83799, 1.5275, 1.76179, 0.664915},
{1.42352, 1.45163, 1.45318, 0.789321},
{1.63669, 1.78145,1.60307, 0.6559},
{1.61749, 1.44287, 1.57405, 0.398447} }
That is, each element of the combined list contains the corresponding elements of lis1 and lis2, with the first three elements being from lis1 and the fourth element from lis2.
Here is what I did to combine them in this fashion:
Transpose[{lis1, lis2}] //. {{a_, b_, c_}, d_} :> {a, b, c, d}
Is there a faster way to achieve this as my lists are huge ?
Join[lis1, List /@ lis2, 2]– Rojo Mar 05 '13 at 19:58Flatten /@ Thread[{lis1, lis2}]... some benchmarking might be in order... – Yves Klett Mar 05 '13 at 20:03List /@ .... This version will be considerably faster still:Join[lis1, Transpose[{lis2}], 2]. – Leonid Shifrin Mar 05 '13 at 20:41