Angharad has asked for the wisdom of the Perl Monks concerning the following question:

Hi people
I wrote a topic on this a couple of days ago, but I didnt really explain myself properly and am not really any further forward with how to tackle it, so I thought I would try again. I have a 7 by 7 PDL matrix as follows:
[ [ 2.7650514 0 0 0 0 + 0 0] [ 0 1.2905497 0 0 0 + 0 0] [ 0 0 0.54930597 0 0 + 0 0] [ 0 0 0 0.23264228 0 + 0 0] [ 0 0 0 0 0.19463077 + 0 0] [ 0 0 0 0 0 0.16669 +291 0] [ 0 0 0 0 0 + 0 0.095157451] ]
I would like to change this so its a 7 column by 34 row matrix, with the above being at the top of the matrix and the remaining rows being populated entirely by zeros. I then would like this all to be placed in another PDL matrix so that I can do some maths on it.
I have considered just extracting the non zero values from the matrix above and then creating the larger matrix by hand, but thats obvoiusly not quite the way to go about this. Any thoughts much appreciated.

Replies are listed 'Best First'.
Re: PDL matrix ... increasing column length
by g0n (Priest) on Sep 09, 2005 at 12:59 UTC
    this works

    use PDL; my $pdl1 = pdl( [ 2.7650514, 0, 0, 0, 0, 0 +, 0], [0, 1.2905497, 0, 0, 0, 0, + 0], [ 0, 0, 0.54930597, 0, 0, + 0, 0], [ 0, 0, 0, 0.23264228, 0, + 0, 0], [ 0, 0, 0, 0, 0.19463077, + 0, 0], [ 0, 0, 0, 0, 0, 0.1666 +9291, 0], [ 0, 0, 0, 0, 0, + 0, 0.095157451]); my $pdl2 = zeroes(27,7); $pdl1=transpose($pdl1); $pdl3 = $pdl1->append($pdl2); $pdl3=transpose($pdl3); print $pdl3;

    Append appends along the first dimension, so you have to transpose first, then transpose back afterwards.

    --------------------------------------------------------------

    $perlquestion=~s/Can I/How do I/g;

Re: PDL matrix ... increasing column length
by newroz (Monk) on Sep 09, 2005 at 14:05 UTC
    Hi,
    May be, more compact version could be written.
    $k=a_7x7_matrix my $pdl2 = zeroes(28,7); my $pdl3 = zeroes(35,28); $k = $k->append($pdl2); $k = $k->glue(1,$pdl3); print $k;