I have a two lists:
list1 = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {x5, y5}} and list2 = {z1, z2, z3, z4, z5} and I want to make a third one like this output = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}, {x4, y4,z4}, {x5, y5, z5}}
What nice command can do the trick? It is to do a ListPlot3D with two lists with more than 10000 entries.
I tried with Map and pure function but it is giving me troubles.
Thank you
Asked
Active
Viewed 178 times
0
lambertmular
- 119
- 7
5 Answers
3
Transpose[Join @@ {Transpose@list1, {list2}}]
or
Join @@@ Transpose[{list1, List /@ list2}]
or
Transpose[{Sequence @@ Transpose@list1, list2}]
or
ArrayReshape[{list1, list2}, Dimensions[list1] + {0, 1}]
(* {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4},{x5,y5,z5}} *)
kglr
- 394,356
- 18
- 477
- 896
2
Try this
Transpose@{list1[[All,1]],list1[[All,2]],list2}
or this
MapThread[{#1[[1]], #1[[2]], #2} &, {list1, list2}]
molekyla777
- 2,888
- 1
- 14
- 28
2
Flatten /@ MapThread[List, {list1, list2}]
or
MapThread[Append, {list1, list2}]
or
Thread[f[list1, list2]] /. f -> Append
Basheer Algohi
- 19,917
- 1
- 31
- 78
1
Here is another one, with MapIndexed
MapIndexed[ {list1[[Last@#2,1]],list1[[Last@#2,2]],#1},list2]
lalmei
- 3,332
- 18
- 26
MapThread[Append, {list1, list2}]– andre314 Jun 13 '14 at 15:42ArrayReshape, see e.g. this question How to partition a list in a specific way? – Artes Jun 13 '14 at 15:54