How to convert diagonal matrix to rectangular matrixIs there a built in function to obtain the back diagonal of a matrix?How to select all elements above the main diagonal of matrix?Diagonal times dense matrix, high precisionHow to extract the list of all matrices from a Block Diagonal Matrix?Get rid of infinity in matrix elements (by separate definition of diagonal and off-diagonal elements)Summation over diagonal blocksHow to transform symmetric matrix to diagonal?Sum of elements in a diagonalReplace diagonal elements in sparse matrixConstructing a block diagonal matrix

Blocks from @ jafe

Why am I getting unevenly-spread results when using $RANDOM?

What was the profession 芸者 (female entertainer) called in Russia?

Is this really the Saturn V computer only, or are there other systems here as well?

Find out what encryptor name my database is using

Why does Trump want a citizenship question on the census?

Gory anime with pink haired girl escaping an asylum

What are the effects of abstaining from eating a certain flavor?

stuck in/at beta

How many Jimmys can fit?

Tesco's Burger Relish Best Before End date number

Other Space Shuttle O-ring failures

Run Bash scripts in folder all at the same time

Decrease spacing between a bullet point and its subbullet point

Passwordless authentication - how and when to invalidate a login code

How do ballistic trajectories work in a ring world?

Wires do not connect in Circuitikz

How do you correct inclination at launch to ISS?

How does one acquire an undead eyeball encased in a gem?

What is the average number of draws it takes before you can not draw any more cards from the Deck of Many Things?

Intern not wearing safety equipment; how could I have handled this differently?

Would denouncing cheaters from an exam make me less likely to receive penalties?

Users forgotting to regenerate PDF before sending it

How to evaluate the performance of open source solver?



How to convert diagonal matrix to rectangular matrix


Is there a built in function to obtain the back diagonal of a matrix?How to select all elements above the main diagonal of matrix?Diagonal times dense matrix, high precisionHow to extract the list of all matrices from a Block Diagonal Matrix?Get rid of infinity in matrix elements (by separate definition of diagonal and off-diagonal elements)Summation over diagonal blocksHow to transform symmetric matrix to diagonal?Sum of elements in a diagonalReplace diagonal elements in sparse matrixConstructing a block diagonal matrix






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








5












$begingroup$


Suppose you have the following diagonal matrix:



DiagonalMatrix[Hold/@a, b, c]//ReleaseHold



a, 0, 0, b, c




How can the above matrix be converted to the following rectangular one?



a, 0, 0, 0, b, c









share|improve this question









New contributor



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






$endgroup$











  • $begingroup$
    Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
    $endgroup$
    – C. E.
    5 mins ago


















5












$begingroup$


Suppose you have the following diagonal matrix:



DiagonalMatrix[Hold/@a, b, c]//ReleaseHold



a, 0, 0, b, c




How can the above matrix be converted to the following rectangular one?



a, 0, 0, 0, b, c









share|improve this question









New contributor



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






$endgroup$











  • $begingroup$
    Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
    $endgroup$
    – C. E.
    5 mins ago














5












5








5





$begingroup$


Suppose you have the following diagonal matrix:



DiagonalMatrix[Hold/@a, b, c]//ReleaseHold



a, 0, 0, b, c




How can the above matrix be converted to the following rectangular one?



a, 0, 0, 0, b, c









share|improve this question









New contributor



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






$endgroup$




Suppose you have the following diagonal matrix:



DiagonalMatrix[Hold/@a, b, c]//ReleaseHold



a, 0, 0, b, c




How can the above matrix be converted to the following rectangular one?



a, 0, 0, 0, b, c






list-manipulation matrix






share|improve this question









New contributor



aleksander_si 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 question









New contributor



aleksander_si 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 question




share|improve this question








edited 8 hours ago







aleksander_si













New contributor



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








asked 8 hours ago









aleksander_sialeksander_si

284 bronze badges




284 bronze badges




New contributor



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




New contributor




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













  • $begingroup$
    Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
    $endgroup$
    – C. E.
    5 mins ago

















  • $begingroup$
    Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
    $endgroup$
    – C. E.
    5 mins ago
















$begingroup$
Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
$endgroup$
– C. E.
5 mins ago





$begingroup$
Could you clarify what should happen for e.g. the matrix a, d, e, 0, 0, b, c as in my answer? Whether my answer is correct or not hinges on this, because it gives a different answer than kglr.
$endgroup$
– C. E.
5 mins ago











2 Answers
2






active

oldest

votes


















1












$begingroup$

kglr's solution fails if the number of elements on the diagonal in any of the preceding rows is larger than the number of elements on the diagonal of the last row.



For example:



PadRight[Flatten /@ a, d, e, 0, 0, b, c] // MatrixForm


Mathematica graphics



m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
PadRight[Flatten /@ m] // MatrixForm


Mathematica graphics



Here is a different solution:



diag = Flatten[#] & /@ Diagonal[m];
ncols = Length@Flatten[diag];
offsets = Most@Prepend[Accumulate[Length /@ diag], 0];
row[values_, offset_, ncols_] := PadRight[ArrayPad[values, offset, 0], ncols]
matrix[diag_, offsets_, ncols_] := MapThread[row[#, #2, ncols] &, diag, offsets]

m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
matrix[diag, offsets, ncols] // MatrixForm


Mathematica graphics






share|improve this answer











$endgroup$




















    6












    $begingroup$

    PadRight[Flatten /@ a, 0, 0, b, c]



    a, 0, 0, 0, b, c







    share|improve this answer









    $endgroup$












    • $begingroup$
      Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
      $endgroup$
      – aleksander_si
      10 mins ago










    • $begingroup$
      Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
      $endgroup$
      – aleksander_si
      2 mins ago














    Your Answer








    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
    );



    );






    aleksander_si is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201672%2fhow-to-convert-diagonal-matrix-to-rectangular-matrix%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









    1












    $begingroup$

    kglr's solution fails if the number of elements on the diagonal in any of the preceding rows is larger than the number of elements on the diagonal of the last row.



    For example:



    PadRight[Flatten /@ a, d, e, 0, 0, b, c] // MatrixForm


    Mathematica graphics



    m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
    PadRight[Flatten /@ m] // MatrixForm


    Mathematica graphics



    Here is a different solution:



    diag = Flatten[#] & /@ Diagonal[m];
    ncols = Length@Flatten[diag];
    offsets = Most@Prepend[Accumulate[Length /@ diag], 0];
    row[values_, offset_, ncols_] := PadRight[ArrayPad[values, offset, 0], ncols]
    matrix[diag_, offsets_, ncols_] := MapThread[row[#, #2, ncols] &, diag, offsets]

    m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
    matrix[diag, offsets, ncols] // MatrixForm


    Mathematica graphics






    share|improve this answer











    $endgroup$

















      1












      $begingroup$

      kglr's solution fails if the number of elements on the diagonal in any of the preceding rows is larger than the number of elements on the diagonal of the last row.



      For example:



      PadRight[Flatten /@ a, d, e, 0, 0, b, c] // MatrixForm


      Mathematica graphics



      m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
      PadRight[Flatten /@ m] // MatrixForm


      Mathematica graphics



      Here is a different solution:



      diag = Flatten[#] & /@ Diagonal[m];
      ncols = Length@Flatten[diag];
      offsets = Most@Prepend[Accumulate[Length /@ diag], 0];
      row[values_, offset_, ncols_] := PadRight[ArrayPad[values, offset, 0], ncols]
      matrix[diag_, offsets_, ncols_] := MapThread[row[#, #2, ncols] &, diag, offsets]

      m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
      matrix[diag, offsets, ncols] // MatrixForm


      Mathematica graphics






      share|improve this answer











      $endgroup$















        1












        1








        1





        $begingroup$

        kglr's solution fails if the number of elements on the diagonal in any of the preceding rows is larger than the number of elements on the diagonal of the last row.



        For example:



        PadRight[Flatten /@ a, d, e, 0, 0, b, c] // MatrixForm


        Mathematica graphics



        m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
        PadRight[Flatten /@ m] // MatrixForm


        Mathematica graphics



        Here is a different solution:



        diag = Flatten[#] & /@ Diagonal[m];
        ncols = Length@Flatten[diag];
        offsets = Most@Prepend[Accumulate[Length /@ diag], 0];
        row[values_, offset_, ncols_] := PadRight[ArrayPad[values, offset, 0], ncols]
        matrix[diag_, offsets_, ncols_] := MapThread[row[#, #2, ncols] &, diag, offsets]

        m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
        matrix[diag, offsets, ncols] // MatrixForm


        Mathematica graphics






        share|improve this answer











        $endgroup$



        kglr's solution fails if the number of elements on the diagonal in any of the preceding rows is larger than the number of elements on the diagonal of the last row.



        For example:



        PadRight[Flatten /@ a, d, e, 0, 0, b, c] // MatrixForm


        Mathematica graphics



        m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
        PadRight[Flatten /@ m] // MatrixForm


        Mathematica graphics



        Here is a different solution:



        diag = Flatten[#] & /@ Diagonal[m];
        ncols = Length@Flatten[diag];
        offsets = Most@Prepend[Accumulate[Length /@ diag], 0];
        row[values_, offset_, ncols_] := PadRight[ArrayPad[values, offset, 0], ncols]
        matrix[diag_, offsets_, ncols_] := MapThread[row[#, #2, ncols] &, diag, offsets]

        m = a, 0, 0, 0, b, c, d, e, f, 0, 0, 0, b, c
        matrix[diag, offsets, ncols] // MatrixForm


        Mathematica graphics







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 3 mins ago

























        answered 12 mins ago









        C. E.C. E.

        52.9k3 gold badges102 silver badges210 bronze badges




        52.9k3 gold badges102 silver badges210 bronze badges























            6












            $begingroup$

            PadRight[Flatten /@ a, 0, 0, b, c]



            a, 0, 0, 0, b, c







            share|improve this answer









            $endgroup$












            • $begingroup$
              Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
              $endgroup$
              – aleksander_si
              10 mins ago










            • $begingroup$
              Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
              $endgroup$
              – aleksander_si
              2 mins ago
















            6












            $begingroup$

            PadRight[Flatten /@ a, 0, 0, b, c]



            a, 0, 0, 0, b, c







            share|improve this answer









            $endgroup$












            • $begingroup$
              Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
              $endgroup$
              – aleksander_si
              10 mins ago










            • $begingroup$
              Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
              $endgroup$
              – aleksander_si
              2 mins ago














            6












            6








            6





            $begingroup$

            PadRight[Flatten /@ a, 0, 0, b, c]



            a, 0, 0, 0, b, c







            share|improve this answer









            $endgroup$



            PadRight[Flatten /@ a, 0, 0, b, c]



            a, 0, 0, 0, b, c








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 7 hours ago









            kglrkglr

            203k10 gold badges232 silver badges463 bronze badges




            203k10 gold badges232 silver badges463 bronze badges











            • $begingroup$
              Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
              $endgroup$
              – aleksander_si
              10 mins ago










            • $begingroup$
              Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
              $endgroup$
              – aleksander_si
              2 mins ago

















            • $begingroup$
              Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
              $endgroup$
              – aleksander_si
              10 mins ago










            • $begingroup$
              Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
              $endgroup$
              – aleksander_si
              2 mins ago
















            $begingroup$
            Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
            $endgroup$
            – aleksander_si
            10 mins ago




            $begingroup$
            Very neat solution!! I just hope I stated the question in a form which makes the problem searchable.
            $endgroup$
            – aleksander_si
            10 mins ago












            $begingroup$
            Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
            $endgroup$
            – aleksander_si
            2 mins ago





            $begingroup$
            Yes, in a situation where the diagonal matrix is as per the below example, then this approach should not be applied:
            $endgroup$
            – aleksander_si
            2 mins ago











            aleksander_si is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            aleksander_si is a new contributor. Be nice, and check out our Code of Conduct.












            aleksander_si is a new contributor. Be nice, and check out our Code of Conduct.











            aleksander_si is a new contributor. Be nice, and check out our Code of Conduct.














            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%2f201672%2fhow-to-convert-diagonal-matrix-to-rectangular-matrix%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

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單