Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Or is it something that could be easily done without the use of modules?

I'm deeply suspicious of questions that seem too easy, but ...

It kinda depends what form you have or obtain the lower-triangle matrix in to start.

But assuming you've loaded the LT matrix into a 2d array, then "converting to a square matrix" consists of padding the upper triangle with zeros, which is one line of perl:

#! perl -slw use strict; use Data::Dump qw[ pp ]; sub fillLTM { my @lt; my $n = 1; push @lt, [ splice @_, 0, $n++ ] while @_; return @lt; } ## read raw data while( my $rawData = <DATA> ) { ## Populate LT matrix my @lt = fillLTM( split ' ', $rawData ); pp \@lt;; ## Pad to square matrix push @{ $lt[$_] }, (0)x( @{ $lt[-1] } - @{ $lt[$_] } ) for 0 .. $# +lt -1;; pp \@lt;; } __DATA__ 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Produces:

C:\test>junk [ [1], [2, 3], [4, 5, 6], [7, 8, 9, 10] ] [ [1, 0, 0, 0], [2, 3, 0, 0], [4, 5, 6, 0], [7, 8, 9, 10] ] [ [1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15] ] [ [1, 0, 0, 0, 0], [2, 3, 0, 0, 0], [4, 5, 6, 0, 0], [7, 8, 9, 10, 0], [11, 12, 13, 14, 15] ]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Convert matrix formats by BrowserUk
in thread Convert matrix formats by naturalsciences

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2018-10-20 23:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...














      Results (119 votes). Check out past polls.

      Notices?