use warnings; use PDL; use PDL::NiceSlice; # Here is my matrix: my $data = sequence(5,5); print "Original:\n$data\n"; # In order to permute columns, I need a *column* vector with the # column numbers that I want. (You'd think a *row* vector would be # more appropriate, but that's not how it works. Alas.) my $indices = sequence(5); # Set up to exchange the second and the third column: #$indices(1:2) .= $indices(2:1); ### should work but doesn't for me $indices(1:2) .= $indices(pdl [2,1]); # Perform the exchange: my $rearranged = $data->dice_axis(0, $indices); print "Column swap:\n$rearranged\n"; # Start over and exchange the fourth and fifth rows: $indices = sequence(5); $indices(3:4) .= $indices(pdl[4,3]); my $further_rearranged = $rearranged->dice_axis(1, $indices); print "Column and row swap:\n$further_rearranged\n";