Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reverse the order of matrix printing using Math::MatrixReal

by kennethk (Abbot)
on May 16, 2014 at 15:35 UTC ( [id://1086332]=note: print w/replies, xml ) Need Help??


in reply to Reverse the order of matrix printing using Math::MatrixReal

From Math::MatrixReal:
$matrix->swap_col( $col1, $col2 ); This method takes two one-based column numbers and swaps the values of each element in each column. $matrix->swap_col(2,3) would replace column 2 in $matrix with column 3, and replace column 3 with column 2.
So presumably you would get your desired result with (untested):
use Text::CSV; use Math::MatrixReal; my $mref = [ [ 'a', 'b', 'c', 'd', 'e' ], ]; my $matrix = Math::MatrixReal->new_from_rows( $mref ); print $matrix; # this will print [ 'a', 'b', 'c', 'd', 'e' ] # I want to reverse the order inside the matrix which I need later on +to do some more operations. Appreciate the help. $matrix->swap_col(1,5); $matrix->swap_col(2,4); #Result: I want the result to be printed like below # print $matrix = [ 'e', 'd', 'c', 'b', 'a' ]
There's also a swap_row method, depending on what you mean by 'reverese the order of matrix output'.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1086332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-19 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found