Specific list manipulation












2












$begingroup$


Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3} and ListY = {y1,y2} and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6} of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1) is associated with z1, say.



How to merge all three lists such that I obtain the following combined list?



{{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}



I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).










share|improve this question











$endgroup$

















    2












    $begingroup$


    Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3} and ListY = {y1,y2} and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6} of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1) is associated with z1, say.



    How to merge all three lists such that I obtain the following combined list?



    {{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}



    I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).










    share|improve this question











    $endgroup$















      2












      2








      2





      $begingroup$


      Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3} and ListY = {y1,y2} and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6} of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1) is associated with z1, say.



      How to merge all three lists such that I obtain the following combined list?



      {{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}



      I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).










      share|improve this question











      $endgroup$




      Suppose I have two lists each of different size, e.g toy case ListX = {x1,x2,x3} and ListY = {y1,y2} and all possible combinations of elements give rise to an element in another list ListZ = {z1,z2,z3,z4,z5,z6} of dimension dim(ListX) x dim(ListY), i.e the tuple (x1,y1) is associated with z1, say.



      How to merge all three lists such that I obtain the following combined list?



      {{{x1,y1},z1}, {{x1,y2},z2}, {{x2,y1},z3}, {{x2,y2},z4}, {{x3,y1},z5},{{x3,y2},z6}}



      I've tried nested tables but I always generate additional items that I don't want. The actual lists I'm dealing with are of dimension O(50) such that the equivalent of ListZ is of dimension O(2500).







      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 11 mins ago









      J. M. is computer-less

      96.8k10303462




      96.8k10303462










      asked 8 hours ago









      CAFCAF

      255110




      255110






















          2 Answers
          2






          active

          oldest

          votes


















          2












          $begingroup$

          This seems to do what you are looking for:



          ListX = {x1, x2, x3};
          ListY = {y1, y2};
          ListZ = {z1, z2, z3, z4, z5, z6};
          Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]


          The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.






          share|improve this answer









          $endgroup$





















            7












            $begingroup$

            Transpose@{Tuples@{ListX, ListY}, ListZ}





            share|improve this answer








            New contributor




            ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$









            • 1




              $begingroup$
              Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
              $endgroup$
              – rmw
              7 hours ago










            • $begingroup$
              Yes. Thanks for reminding me that.
              $endgroup$
              – ukar
              4 hours ago











            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "387"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192128%2fspecific-list-manipulation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$

            This seems to do what you are looking for:



            ListX = {x1, x2, x3};
            ListY = {y1, y2};
            ListZ = {z1, z2, z3, z4, z5, z6};
            Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]


            The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.






            share|improve this answer









            $endgroup$


















              2












              $begingroup$

              This seems to do what you are looking for:



              ListX = {x1, x2, x3};
              ListY = {y1, y2};
              ListZ = {z1, z2, z3, z4, z5, z6};
              Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]


              The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.






              share|improve this answer









              $endgroup$
















                2












                2








                2





                $begingroup$

                This seems to do what you are looking for:



                ListX = {x1, x2, x3};
                ListY = {y1, y2};
                ListZ = {z1, z2, z3, z4, z5, z6};
                Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]


                The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.






                share|improve this answer









                $endgroup$



                This seems to do what you are looking for:



                ListX = {x1, x2, x3};
                ListY = {y1, y2};
                ListZ = {z1, z2, z3, z4, z5, z6};
                Partition[Riffle[Flatten[Outer[List, ListX, ListY], 1], ListZ], 2]


                The Outer product gives all the pairs, but they are nested funny so you need to Flatten. Riffle does the interleaving of the Outer product with ListZ, and again it's not quite got your desired structure, but Partition fixes that.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 8 hours ago









                bill sbill s

                53.6k376152




                53.6k376152























                    7












                    $begingroup$

                    Transpose@{Tuples@{ListX, ListY}, ListZ}





                    share|improve this answer








                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    $endgroup$









                    • 1




                      $begingroup$
                      Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                      $endgroup$
                      – rmw
                      7 hours ago










                    • $begingroup$
                      Yes. Thanks for reminding me that.
                      $endgroup$
                      – ukar
                      4 hours ago
















                    7












                    $begingroup$

                    Transpose@{Tuples@{ListX, ListY}, ListZ}





                    share|improve this answer








                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    $endgroup$









                    • 1




                      $begingroup$
                      Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                      $endgroup$
                      – rmw
                      7 hours ago










                    • $begingroup$
                      Yes. Thanks for reminding me that.
                      $endgroup$
                      – ukar
                      4 hours ago














                    7












                    7








                    7





                    $begingroup$

                    Transpose@{Tuples@{ListX, ListY}, ListZ}





                    share|improve this answer








                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    $endgroup$



                    Transpose@{Tuples@{ListX, ListY}, ListZ}






                    share|improve this answer








                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer






                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 7 hours ago









                    ukarukar

                    691




                    691




                    New contributor




                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    ukar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.








                    • 1




                      $begingroup$
                      Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                      $endgroup$
                      – rmw
                      7 hours ago










                    • $begingroup$
                      Yes. Thanks for reminding me that.
                      $endgroup$
                      – ukar
                      4 hours ago














                    • 1




                      $begingroup$
                      Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                      $endgroup$
                      – rmw
                      7 hours ago










                    • $begingroup$
                      Yes. Thanks for reminding me that.
                      $endgroup$
                      – ukar
                      4 hours ago








                    1




                    1




                    $begingroup$
                    Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                    $endgroup$
                    – rmw
                    7 hours ago




                    $begingroup$
                    Very nice solution! You can also use Thread instead of Transpose:Thread@{Tuples@{ListX, ListY}, ListZ}
                    $endgroup$
                    – rmw
                    7 hours ago












                    $begingroup$
                    Yes. Thanks for reminding me that.
                    $endgroup$
                    – ukar
                    4 hours ago




                    $begingroup$
                    Yes. Thanks for reminding me that.
                    $endgroup$
                    – ukar
                    4 hours ago


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Mathematica Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192128%2fspecific-list-manipulation%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to label and detect the document text images

                    Tabula Rosettana

                    Aureus (color)