Data re-structure by Thread

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Thread can do this



Thread[a, b, c, d]



a, b, a, c, a, d



But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization



Thread[a, b, x, y, z, w, u, v]


which just raises an error.



Here what is intended for is



a, b, x, y, a, b, z, w, a, b, u, v


So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?










share|improve this question

























    up vote
    2
    down vote

    favorite












    Thread can do this



    Thread[a, b, c, d]



    a, b, a, c, a, d



    But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization



    Thread[a, b, x, y, z, w, u, v]


    which just raises an error.



    Here what is intended for is



    a, b, x, y, a, b, z, w, a, b, u, v


    So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Thread can do this



      Thread[a, b, c, d]



      a, b, a, c, a, d



      But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization



      Thread[a, b, x, y, z, w, u, v]


      which just raises an error.



      Here what is intended for is



      a, b, x, y, a, b, z, w, a, b, u, v


      So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?










      share|improve this question













      Thread can do this



      Thread[a, b, c, d]



      a, b, a, c, a, d



      But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization



      Thread[a, b, x, y, z, w, u, v]


      which just raises an error.



      Here what is intended for is



      a, b, x, y, a, b, z, w, a, b, u, v


      So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?







      list-manipulation data data-structures






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      Αλέξανδρος Ζεγγ

      1,723720




      1,723720




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          A level specification can help (we have to specify the head to thread over, too):



          Thread[a, b, x, y, z, w, u, v, List, 2]



          a, b, x, y, a, b, z, w, a, b, u, v




          Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:



          Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2], 
          List, 2] // Developer`PackedArrayQ // AbsoluteTiming

          Transpose[
          ConstantArray[RandomReal[-1, 1, 2], 1000000],
          RandomReal[-1, 1, 1000000, 2]

          ] // Developer`PackedArrayQ // AbsoluteTiming



          0.347755, False



          0.046035, True







          share|improve this answer






















          • It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
            – Î‘λέξανδρος Ζεγγ
            2 hours ago







          • 1




            For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
            – Henrik Schumacher
            2 hours ago







          • 1




            Sorry, do you mean f[..., n] in the latter?
            – Î‘λέξανδρος Ζεγγ
            2 hours ago






          • 1




            Yes. But I fixed the comment already. Thanks for the accept btw.
            – Henrik Schumacher
            2 hours ago






          • 1




            Your information on packed array is valuable.
            – Î‘λέξανδρος Ζεγγ
            1 hour 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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f182022%2fdata-re-structure-by-thread%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          A level specification can help (we have to specify the head to thread over, too):



          Thread[a, b, x, y, z, w, u, v, List, 2]



          a, b, x, y, a, b, z, w, a, b, u, v




          Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:



          Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2], 
          List, 2] // Developer`PackedArrayQ // AbsoluteTiming

          Transpose[
          ConstantArray[RandomReal[-1, 1, 2], 1000000],
          RandomReal[-1, 1, 1000000, 2]

          ] // Developer`PackedArrayQ // AbsoluteTiming



          0.347755, False



          0.046035, True







          share|improve this answer






















          • It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
            – Î‘λέξανδρος Ζεγγ
            2 hours ago







          • 1




            For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
            – Henrik Schumacher
            2 hours ago







          • 1




            Sorry, do you mean f[..., n] in the latter?
            – Î‘λέξανδρος Ζεγγ
            2 hours ago






          • 1




            Yes. But I fixed the comment already. Thanks for the accept btw.
            – Henrik Schumacher
            2 hours ago






          • 1




            Your information on packed array is valuable.
            – Î‘λέξανδρος Ζεγγ
            1 hour ago














          up vote
          3
          down vote



          accepted










          A level specification can help (we have to specify the head to thread over, too):



          Thread[a, b, x, y, z, w, u, v, List, 2]



          a, b, x, y, a, b, z, w, a, b, u, v




          Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:



          Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2], 
          List, 2] // Developer`PackedArrayQ // AbsoluteTiming

          Transpose[
          ConstantArray[RandomReal[-1, 1, 2], 1000000],
          RandomReal[-1, 1, 1000000, 2]

          ] // Developer`PackedArrayQ // AbsoluteTiming



          0.347755, False



          0.046035, True







          share|improve this answer






















          • It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
            – Î‘λέξανδρος Ζεγγ
            2 hours ago







          • 1




            For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
            – Henrik Schumacher
            2 hours ago







          • 1




            Sorry, do you mean f[..., n] in the latter?
            – Î‘λέξανδρος Ζεγγ
            2 hours ago






          • 1




            Yes. But I fixed the comment already. Thanks for the accept btw.
            – Henrik Schumacher
            2 hours ago






          • 1




            Your information on packed array is valuable.
            – Î‘λέξανδρος Ζεγγ
            1 hour ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          A level specification can help (we have to specify the head to thread over, too):



          Thread[a, b, x, y, z, w, u, v, List, 2]



          a, b, x, y, a, b, z, w, a, b, u, v




          Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:



          Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2], 
          List, 2] // Developer`PackedArrayQ // AbsoluteTiming

          Transpose[
          ConstantArray[RandomReal[-1, 1, 2], 1000000],
          RandomReal[-1, 1, 1000000, 2]

          ] // Developer`PackedArrayQ // AbsoluteTiming



          0.347755, False



          0.046035, True







          share|improve this answer














          A level specification can help (we have to specify the head to thread over, too):



          Thread[a, b, x, y, z, w, u, v, List, 2]



          a, b, x, y, a, b, z, w, a, b, u, v




          Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:



          Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2], 
          List, 2] // Developer`PackedArrayQ // AbsoluteTiming

          Transpose[
          ConstantArray[RandomReal[-1, 1, 2], 1000000],
          RandomReal[-1, 1, 1000000, 2]

          ] // Developer`PackedArrayQ // AbsoluteTiming



          0.347755, False



          0.046035, True








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 2 hours ago









          Henrik Schumacher

          38.2k250110




          38.2k250110











          • It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
            – Î‘λέξανδρος Ζεγγ
            2 hours ago







          • 1




            For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
            – Henrik Schumacher
            2 hours ago







          • 1




            Sorry, do you mean f[..., n] in the latter?
            – Î‘λέξανδρος Ζεγγ
            2 hours ago






          • 1




            Yes. But I fixed the comment already. Thanks for the accept btw.
            – Henrik Schumacher
            2 hours ago






          • 1




            Your information on packed array is valuable.
            – Î‘λέξανδρος Ζεγγ
            1 hour ago
















          • It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
            – Î‘λέξανδρος Ζεγγ
            2 hours ago







          • 1




            For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
            – Henrik Schumacher
            2 hours ago







          • 1




            Sorry, do you mean f[..., n] in the latter?
            – Î‘λέξανδρος Ζεγγ
            2 hours ago






          • 1




            Yes. But I fixed the comment already. Thanks for the accept btw.
            – Henrik Schumacher
            2 hours ago






          • 1




            Your information on packed array is valuable.
            – Î‘λέξανδρος Ζεγγ
            1 hour ago















          It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
          – Î‘λέξανδρος Ζεγγ
          2 hours ago





          It seems it. So any clarification for the curly brackets around 2 here? The F1 documentation of Thread does not mention level specification.
          – Î‘λέξανδρος Ζεγγ
          2 hours ago





          1




          1




          For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
          – Henrik Schumacher
          2 hours ago





          For level specifications, f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".
          – Henrik Schumacher
          2 hours ago





          1




          1




          Sorry, do you mean f[..., n] in the latter?
          – Î‘λέξανδρος Ζεγγ
          2 hours ago




          Sorry, do you mean f[..., n] in the latter?
          – Î‘λέξανδρος Ζεγγ
          2 hours ago




          1




          1




          Yes. But I fixed the comment already. Thanks for the accept btw.
          – Henrik Schumacher
          2 hours ago




          Yes. But I fixed the comment already. Thanks for the accept btw.
          – Henrik Schumacher
          2 hours ago




          1




          1




          Your information on packed array is valuable.
          – Î‘λέξανδρος Ζεγγ
          1 hour ago




          Your information on packed array is valuable.
          – Î‘λέξανδρος Ζεγγ
          1 hour ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182022%2fdata-re-structure-by-thread%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          White Anglo-Saxon Protestant

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          One-line joke