8
$\begingroup$

i hope some of you can support to solve my problem, i need to work on data in the following way, where the length of each of the lists or sublists is equal. As an example i want to share the data-pattern with you:

list1={a,b,c};
list2={{d,e,f},{g,h,i},......} (in reality the number of sublists in list2 is about 30)
data=list2[[1]]

the goal is now to combine these lists in the following form { {{a,d},{b,e},{c,f}}, {{a,g},...} ...} .


The next step to plot it or to create a fit-formula. The values of list1 should be always plotted as the x-Data. I created some of the most interesting datasets as follows: `

plottedList=Table[{list1[[k]], data[[k]]}, {k, 1, Length[data]}]
ListPlot[plottedList]

My Problem is that i now would need to plot all of the data-pairs and combine the data to create the lists which i can find a linear or nonlinear fit.


I hope you can give me some advice, Best Chris!

$\endgroup$
1
  • 1
    $\begingroup$ To answer the second part of your question (which probably should be its own separate question altogether), it would be much more helpful if you could share a portion of the actual numerical data and specify what problems you encountered that are not solved by the approaches proposed in the answers below. $\endgroup$
    – MarcoB
    Commented Dec 21, 2021 at 15:30

4 Answers 4

8
$\begingroup$

A minor variation based on @kglr's answer.

list1 = {a, b, c};
list2 = {{d, e, f}, {g, h, i}};
MapThread[List, {list1, #}] & /@ list2

Using Transpose:

Transpose[{list1, #}] & /@ list2

Result:

{{{a, d}, {b, e}, {c, f}}, {{a, g}, {b, h}, {c, i}}}

$\endgroup$
7
$\begingroup$
list1 = {a, b, c};
list2 = {{d, e, f}, {g, h, i}};

Map[Thread[{list1, #}] &] @ list2
{{{a, d}, {b, e}, {c, f}}, {{a, g}, {b, h}, {c, i}}}
$\endgroup$
6
$\begingroup$
Inner[{#2,#1}&,list2,list1,List]

(* {{{a, d}, {b, e}, {c, f}}, {{a, g}, {b, h}, {c, i}}} *)

A Slot-free version

J. M. can't deal with it (in a comment) gives the following neat modification:

Inner[ReverseApplied[List], list2, list1, List]

Lists

list1 = {a, b, c};
list2 = {{d, e, f}, {g, h, i}};
$\endgroup$
1
  • 1
    $\begingroup$ Very nice. Here's a slot-free version: Inner[ReverseApplied[List], list2, list1, List] $\endgroup$ Commented Dec 22, 2021 at 13:27
3
$\begingroup$
la = {a, b, c};

lb = {{d, e, f}, {g, h, i}};

Using Table

Table[Transpose[{la, lb[[n]]}], {n, 2}]

{{{a, d}, {b, e}, {c, f}}, {{a, g}, {b, h}, {c, i}}}

Using ReplacePart

ReplacePart[lb, n_ :> Transpose[{la, lb[[n]]}]]

{{{a, d}, {b, e}, {c, f}}, {{a, g}, {b, h}, {c, i}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.