Message Boards Message Boards

0
|
3396 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

ReplaceAll, MapThread, Rule in sequence

Hi, I have


GG1 = {{1,2,3,4.},{5,6,7,8}}


result ={ {{a,b},{a,c},{a,d},{a,a}},{{a,b1},{a,c1},{a,d1},{a,a1}} }

I'd like obtain : res1 = { {{1,b},{2,c},{3,d},{4,a}},{{5,b1},{6,c1},{7,d1},{8,a1}} } the length of result or GG1 is variable depending on the test case.

I have tried with this, but it doesn't run.

res1 = [ReplaceAll[result, MapThread[ Rule, {result[[i, All, 1]], GG1[[i]] &} , {i, 1, Length[GG1]}]]]

I hope in your help

Thank you

3 Replies

Thank you

Posted 10 years ago

In[17]:= MapThread[List, {GG1, result[[All, All, 2]]}, 2]

Out[17]= {{{1, b}, {2, c}, {3, d}, {4, a}}, {{5, b1}, {6, c1}, {7, d1}, {8, a1}}}

POSTED BY: David Keith
Posted 10 years ago
Map[Transpose, Transpose[{GG1, Map[Last, result, {-2}]}]]
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract