in reply to Re^3: An efficient, scalable matrix transformation algorithm
in thread An efficient, scalable matrix transformation algorithm
FWIW, this transpose runs ~3.5 times faster than the loop you had (on my machine, anyway). The message here is that the trick with Perl is to replace a for or while by map or grep if possible !
sub transpose_gmch { my ($matrix) = shift ; my @result = () ; my $lc = $#{$matrix->[0]} ; for my $col (0..$lc) { push @result, [map $_->[$col], @$matrix] ; } ; return( \@result ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: An efficient, scalable matrix transformation algorithm
by Luftkissenboot (Novice) on Jan 29, 2009 at 07:37 UTC |