Averaging elements of a list of matrices over time

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











up vote
2
down vote

favorite












Suppose that I have a time series of a matrix, say, for 3 periods.



t1=0,3,0,6,0,0,3,6,0;
t2=0,6,0,3,0,3,0,6,0;
t3=0,3,6,3,0,6,3,3,0;



enter image description here




I want to take the average of each cell [i,j] over time by considering the number of non-zero elements only as follows:




Blockquote




I went through the documentation of Matrix Operations but I could not find any thing close to what I describe above. Of course, one can use Flatten, Sum and Partition to accomplish what I want. However, I like to have a more elegant way to do the job using matrix structure.










share|improve this question

























    up vote
    2
    down vote

    favorite












    Suppose that I have a time series of a matrix, say, for 3 periods.



    t1=0,3,0,6,0,0,3,6,0;
    t2=0,6,0,3,0,3,0,6,0;
    t3=0,3,6,3,0,6,3,3,0;



    enter image description here




    I want to take the average of each cell [i,j] over time by considering the number of non-zero elements only as follows:




    Blockquote




    I went through the documentation of Matrix Operations but I could not find any thing close to what I describe above. Of course, one can use Flatten, Sum and Partition to accomplish what I want. However, I like to have a more elegant way to do the job using matrix structure.










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Suppose that I have a time series of a matrix, say, for 3 periods.



      t1=0,3,0,6,0,0,3,6,0;
      t2=0,6,0,3,0,3,0,6,0;
      t3=0,3,6,3,0,6,3,3,0;



      enter image description here




      I want to take the average of each cell [i,j] over time by considering the number of non-zero elements only as follows:




      Blockquote




      I went through the documentation of Matrix Operations but I could not find any thing close to what I describe above. Of course, one can use Flatten, Sum and Partition to accomplish what I want. However, I like to have a more elegant way to do the job using matrix structure.










      share|improve this question













      Suppose that I have a time series of a matrix, say, for 3 periods.



      t1=0,3,0,6,0,0,3,6,0;
      t2=0,6,0,3,0,3,0,6,0;
      t3=0,3,6,3,0,6,3,3,0;



      enter image description here




      I want to take the average of each cell [i,j] over time by considering the number of non-zero elements only as follows:




      Blockquote




      I went through the documentation of Matrix Operations but I could not find any thing close to what I describe above. Of course, one can use Flatten, Sum and Partition to accomplish what I want. However, I like to have a more elegant way to do the job using matrix structure.







      matrix






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 53 mins ago









      Tugrul Temel

      525113




      525113




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Quiet @ Block[Indeterminate = 0, Total[#] / Total[Unitize @ #]] & @ t1, t2, t3

          % // MatrixForm // TeXForm



          $left(
          beginarrayccc
          0 & 4 & 6 \
          4 & 0 & frac92 \
          3 & 5 & 0 \
          endarray
          right)$




          Also



          Total[t1, t2, t3] / (Total[Unitize @ t1, t2, t3] /. 0 -> 1)



          same result







          share|improve this answer






















          • Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
            – Tugrul Temel
            27 mins ago










          • Thank you @TugrulTemel for the accept and kind words.
            – kglr
            25 mins ago






          • 2




            First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
            – Okkes Dulgerci
            21 mins ago











          • Thank you @OkkesDulgerci. Forgot to Quiet.
            – kglr
            15 mins ago










          • @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
            – Tugrul Temel
            14 mins ago

















          up vote
          2
          down vote













          Total[t1, t2, t3]/Clip[Total[Unitize@t1, t2, t3], 1, Infinity]





          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: 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%2f184641%2faveraging-elements-of-a-list-of-matrices-over-time%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Quiet @ Block[Indeterminate = 0, Total[#] / Total[Unitize @ #]] & @ t1, t2, t3

            % // MatrixForm // TeXForm



            $left(
            beginarrayccc
            0 & 4 & 6 \
            4 & 0 & frac92 \
            3 & 5 & 0 \
            endarray
            right)$




            Also



            Total[t1, t2, t3] / (Total[Unitize @ t1, t2, t3] /. 0 -> 1)



            same result







            share|improve this answer






















            • Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
              – Tugrul Temel
              27 mins ago










            • Thank you @TugrulTemel for the accept and kind words.
              – kglr
              25 mins ago






            • 2




              First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
              – Okkes Dulgerci
              21 mins ago











            • Thank you @OkkesDulgerci. Forgot to Quiet.
              – kglr
              15 mins ago










            • @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
              – Tugrul Temel
              14 mins ago














            up vote
            3
            down vote



            accepted










            Quiet @ Block[Indeterminate = 0, Total[#] / Total[Unitize @ #]] & @ t1, t2, t3

            % // MatrixForm // TeXForm



            $left(
            beginarrayccc
            0 & 4 & 6 \
            4 & 0 & frac92 \
            3 & 5 & 0 \
            endarray
            right)$




            Also



            Total[t1, t2, t3] / (Total[Unitize @ t1, t2, t3] /. 0 -> 1)



            same result







            share|improve this answer






















            • Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
              – Tugrul Temel
              27 mins ago










            • Thank you @TugrulTemel for the accept and kind words.
              – kglr
              25 mins ago






            • 2




              First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
              – Okkes Dulgerci
              21 mins ago











            • Thank you @OkkesDulgerci. Forgot to Quiet.
              – kglr
              15 mins ago










            • @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
              – Tugrul Temel
              14 mins ago












            up vote
            3
            down vote



            accepted







            up vote
            3
            down vote



            accepted






            Quiet @ Block[Indeterminate = 0, Total[#] / Total[Unitize @ #]] & @ t1, t2, t3

            % // MatrixForm // TeXForm



            $left(
            beginarrayccc
            0 & 4 & 6 \
            4 & 0 & frac92 \
            3 & 5 & 0 \
            endarray
            right)$




            Also



            Total[t1, t2, t3] / (Total[Unitize @ t1, t2, t3] /. 0 -> 1)



            same result







            share|improve this answer














            Quiet @ Block[Indeterminate = 0, Total[#] / Total[Unitize @ #]] & @ t1, t2, t3

            % // MatrixForm // TeXForm



            $left(
            beginarrayccc
            0 & 4 & 6 \
            4 & 0 & frac92 \
            3 & 5 & 0 \
            endarray
            right)$




            Also



            Total[t1, t2, t3] / (Total[Unitize @ t1, t2, t3] /. 0 -> 1)



            same result








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 16 mins ago

























            answered 43 mins ago









            kglr

            167k8189392




            167k8189392











            • Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
              – Tugrul Temel
              27 mins ago










            • Thank you @TugrulTemel for the accept and kind words.
              – kglr
              25 mins ago






            • 2




              First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
              – Okkes Dulgerci
              21 mins ago











            • Thank you @OkkesDulgerci. Forgot to Quiet.
              – kglr
              15 mins ago










            • @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
              – Tugrul Temel
              14 mins ago
















            • Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
              – Tugrul Temel
              27 mins ago










            • Thank you @TugrulTemel for the accept and kind words.
              – kglr
              25 mins ago






            • 2




              First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
              – Okkes Dulgerci
              21 mins ago











            • Thank you @OkkesDulgerci. Forgot to Quiet.
              – kglr
              15 mins ago










            • @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
              – Tugrul Temel
              14 mins ago















            Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
            – Tugrul Temel
            27 mins ago




            Your answers are perfect, just the type of answers I was thinking of. The first answer looks more elegant, though.
            – Tugrul Temel
            27 mins ago












            Thank you @TugrulTemel for the accept and kind words.
            – kglr
            25 mins ago




            Thank you @TugrulTemel for the accept and kind words.
            – kglr
            25 mins ago




            2




            2




            First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
            – Okkes Dulgerci
            21 mins ago





            First solution gives a warning on M11.3 Power::infy: Infinite expression 1/0 encountered.
            – Okkes Dulgerci
            21 mins ago













            Thank you @OkkesDulgerci. Forgot to Quiet.
            – kglr
            15 mins ago




            Thank you @OkkesDulgerci. Forgot to Quiet.
            – kglr
            15 mins ago












            @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
            – Tugrul Temel
            14 mins ago




            @kglr: Yes, I was going to ask why we receive warnings from the first method. There is no room for warning because if all elements are zero, then the average is zero.
            – Tugrul Temel
            14 mins ago










            up vote
            2
            down vote













            Total[t1, t2, t3]/Clip[Total[Unitize@t1, t2, t3], 1, Infinity]





            share|improve this answer
























              up vote
              2
              down vote













              Total[t1, t2, t3]/Clip[Total[Unitize@t1, t2, t3], 1, Infinity]





              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                Total[t1, t2, t3]/Clip[Total[Unitize@t1, t2, t3], 1, Infinity]





                share|improve this answer












                Total[t1, t2, t3]/Clip[Total[Unitize@t1, t2, t3], 1, Infinity]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 29 mins ago









                Alan

                6,0541124




                6,0541124



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184641%2faveraging-elements-of-a-list-of-matrices-over-time%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

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

                    Confectionery