List Interval Sum











up vote
2
down vote

favorite












I am doing a large data-set computation. Among those computational steps, in one step I need to do a sum with a pattern: Sum the elements with same interval.



For example, for a list from 1 to 9; With the interval being set to 3 manually. So it could be other values in different cases.



And the list would be calculated as:



1 + 4 + 7 = 12;
2 + 5 + 8 = 15;
3 + 6 + 9 = 18;


So for list = Range[1,9],the final desired result would be {12,15,18} in this example. I attached an illustration for a further elaboration: sum the element with the same color when interval = 3:



The example illustration, sum same color with interval equals to 3 in this case



Thanks for @Chris's Answer, the above case could be solved by:



 Total[Partition[Range[9], 3]]


Edit my original question from here:



But what I actually want to do is only sum "N" numbers in a time. N is settled and when N = 3 in below example:



enter image description here



It should be computed by :



1 + 4 + 7 = 12;
2 + 5 + 8 = 15;
3 + 6 + 9 = 18;
10 + 13 + 16 = 39;
11 + 14 + 17 = 42;
12 + 15 + 18 = 45;


Hereby the result would be {12,15,18,39,42,45}



I think this might be not hard, but I just can't think it very clearly when I want to utilize the parallelization characteristics of MMA and trying to avoid Unpacked Array results.










share|improve this question




























    up vote
    2
    down vote

    favorite












    I am doing a large data-set computation. Among those computational steps, in one step I need to do a sum with a pattern: Sum the elements with same interval.



    For example, for a list from 1 to 9; With the interval being set to 3 manually. So it could be other values in different cases.



    And the list would be calculated as:



    1 + 4 + 7 = 12;
    2 + 5 + 8 = 15;
    3 + 6 + 9 = 18;


    So for list = Range[1,9],the final desired result would be {12,15,18} in this example. I attached an illustration for a further elaboration: sum the element with the same color when interval = 3:



    The example illustration, sum same color with interval equals to 3 in this case



    Thanks for @Chris's Answer, the above case could be solved by:



     Total[Partition[Range[9], 3]]


    Edit my original question from here:



    But what I actually want to do is only sum "N" numbers in a time. N is settled and when N = 3 in below example:



    enter image description here



    It should be computed by :



    1 + 4 + 7 = 12;
    2 + 5 + 8 = 15;
    3 + 6 + 9 = 18;
    10 + 13 + 16 = 39;
    11 + 14 + 17 = 42;
    12 + 15 + 18 = 45;


    Hereby the result would be {12,15,18,39,42,45}



    I think this might be not hard, but I just can't think it very clearly when I want to utilize the parallelization characteristics of MMA and trying to avoid Unpacked Array results.










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am doing a large data-set computation. Among those computational steps, in one step I need to do a sum with a pattern: Sum the elements with same interval.



      For example, for a list from 1 to 9; With the interval being set to 3 manually. So it could be other values in different cases.



      And the list would be calculated as:



      1 + 4 + 7 = 12;
      2 + 5 + 8 = 15;
      3 + 6 + 9 = 18;


      So for list = Range[1,9],the final desired result would be {12,15,18} in this example. I attached an illustration for a further elaboration: sum the element with the same color when interval = 3:



      The example illustration, sum same color with interval equals to 3 in this case



      Thanks for @Chris's Answer, the above case could be solved by:



       Total[Partition[Range[9], 3]]


      Edit my original question from here:



      But what I actually want to do is only sum "N" numbers in a time. N is settled and when N = 3 in below example:



      enter image description here



      It should be computed by :



      1 + 4 + 7 = 12;
      2 + 5 + 8 = 15;
      3 + 6 + 9 = 18;
      10 + 13 + 16 = 39;
      11 + 14 + 17 = 42;
      12 + 15 + 18 = 45;


      Hereby the result would be {12,15,18,39,42,45}



      I think this might be not hard, but I just can't think it very clearly when I want to utilize the parallelization characteristics of MMA and trying to avoid Unpacked Array results.










      share|improve this question















      I am doing a large data-set computation. Among those computational steps, in one step I need to do a sum with a pattern: Sum the elements with same interval.



      For example, for a list from 1 to 9; With the interval being set to 3 manually. So it could be other values in different cases.



      And the list would be calculated as:



      1 + 4 + 7 = 12;
      2 + 5 + 8 = 15;
      3 + 6 + 9 = 18;


      So for list = Range[1,9],the final desired result would be {12,15,18} in this example. I attached an illustration for a further elaboration: sum the element with the same color when interval = 3:



      The example illustration, sum same color with interval equals to 3 in this case



      Thanks for @Chris's Answer, the above case could be solved by:



       Total[Partition[Range[9], 3]]


      Edit my original question from here:



      But what I actually want to do is only sum "N" numbers in a time. N is settled and when N = 3 in below example:



      enter image description here



      It should be computed by :



      1 + 4 + 7 = 12;
      2 + 5 + 8 = 15;
      3 + 6 + 9 = 18;
      10 + 13 + 16 = 39;
      11 + 14 + 17 = 42;
      12 + 15 + 18 = 45;


      Hereby the result would be {12,15,18,39,42,45}



      I think this might be not hard, but I just can't think it very clearly when I want to utilize the parallelization characteristics of MMA and trying to avoid Unpacked Array results.







      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago

























      asked 2 hours ago









      cj9435042

      33716




      33716






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          Total[Partition[Range[9], 3]]



          {12, 15, 18}




          Update for revised question:



          r = Range[18]    

          Total /@ Flatten[Partition[#, 3] & /@ {r[[1 ;; ;; 3]], r[[2 ;; ;; 3]], r[[3 ;; ;; 3]]}, 1]





          share|improve this answer























          • Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
            – cj9435042
            1 hour ago


















          up vote
          1
          down vote













          Total@Take[Range@9, {#, -1, 3}] & /@ Range@3    



          {12, 15, 18}




          or..



          Total /@ Transpose@Partition[Range@9, 3]   



          {12, 15, 18}







          share|improve this answer





















            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: 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%2f187334%2flist-interval-sum%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








            up vote
            3
            down vote













            Total[Partition[Range[9], 3]]



            {12, 15, 18}




            Update for revised question:



            r = Range[18]    

            Total /@ Flatten[Partition[#, 3] & /@ {r[[1 ;; ;; 3]], r[[2 ;; ;; 3]], r[[3 ;; ;; 3]]}, 1]





            share|improve this answer























            • Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
              – cj9435042
              1 hour ago















            up vote
            3
            down vote













            Total[Partition[Range[9], 3]]



            {12, 15, 18}




            Update for revised question:



            r = Range[18]    

            Total /@ Flatten[Partition[#, 3] & /@ {r[[1 ;; ;; 3]], r[[2 ;; ;; 3]], r[[3 ;; ;; 3]]}, 1]





            share|improve this answer























            • Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
              – cj9435042
              1 hour ago













            up vote
            3
            down vote










            up vote
            3
            down vote









            Total[Partition[Range[9], 3]]



            {12, 15, 18}




            Update for revised question:



            r = Range[18]    

            Total /@ Flatten[Partition[#, 3] & /@ {r[[1 ;; ;; 3]], r[[2 ;; ;; 3]], r[[3 ;; ;; 3]]}, 1]





            share|improve this answer














            Total[Partition[Range[9], 3]]



            {12, 15, 18}




            Update for revised question:



            r = Range[18]    

            Total /@ Flatten[Partition[#, 3] & /@ {r[[1 ;; ;; 3]], r[[2 ;; ;; 3]], r[[3 ;; ;; 3]]}, 1]






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 28 mins ago

























            answered 2 hours ago









            Chris

            52116




            52116












            • Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
              – cj9435042
              1 hour ago


















            • Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
              – cj9435042
              1 hour ago
















            Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
            – cj9435042
            1 hour ago




            Hi Chris, sorry I wasn't clarify the problem clearly. I just updated my question would you still interest to help?
            – cj9435042
            1 hour ago










            up vote
            1
            down vote













            Total@Take[Range@9, {#, -1, 3}] & /@ Range@3    



            {12, 15, 18}




            or..



            Total /@ Transpose@Partition[Range@9, 3]   



            {12, 15, 18}







            share|improve this answer

























              up vote
              1
              down vote













              Total@Take[Range@9, {#, -1, 3}] & /@ Range@3    



              {12, 15, 18}




              or..



              Total /@ Transpose@Partition[Range@9, 3]   



              {12, 15, 18}







              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                Total@Take[Range@9, {#, -1, 3}] & /@ Range@3    



                {12, 15, 18}




                or..



                Total /@ Transpose@Partition[Range@9, 3]   



                {12, 15, 18}







                share|improve this answer












                Total@Take[Range@9, {#, -1, 3}] & /@ Range@3    



                {12, 15, 18}




                or..



                Total /@ Transpose@Partition[Range@9, 3]   



                {12, 15, 18}








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                J42161217

                3,597220




                3,597220






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.


                    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%2f187334%2flist-interval-sum%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

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕