Re: Reordering Arrays.
On Mon, 11 Aug 2003, Mark Fowler wrote: > I have this: > >[ [ 1, 2, 3, ], > [ 5, 6, 7, ], ] > > And I want this: > >[ [ 1, 5, ], > [ 2, 6, ], > [ 3, 7, ], ] > > How do I do that? I mean, I can write this code: Use APL. Alternatively, something like: map { my $a = $_; map { $arr->[$_]->[$a] } (0..$#arr) } (0..$#{$arr->[0]}) S. > But does anyone know a module that can do this? Any super fast cleverness > that I don't want to even think about? You could tie it to something that just pretends the coordinates are the other way around? S. -- Shevekhttp://www.anarres.org/ I am the Borg. http://www.gothnicity.org/
Re: Reordering Arrays.
On Tue, 12 Aug 2003, Dan Brook wrote: > If you nab mapcar[0] this is insanely simple Interesting. Is there something like this on the CPAN? It's a bit hard to put a page from perlmonks into a PREREQ_PM Mark. -- #!/usr/bin/perl -T use strict; use warnings; print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
Re: Reordering Arrays.
On Wed, 13 Aug 2003 11:23:41 +0100 (BST) Mark Fowler <[EMAIL PROTECTED]> wrote: > On Tue, 12 Aug 2003, Dan Brook wrote: > > > If you nab mapcar[0] this is insanely simple > > Interesting. Is there something like this on the CPAN? It's a bit > hard to put a page from perlmonks into a PREREQ_PM There's nothing quite like mapcar with regards to it's simplicity[0], but there is the transpose method from Math::Matrix[1] which should do it e.g shell> perl -MData::Dumper -MMath::Matrix -e 'print Dumper( Math::Matrix->new([1..3],[5..7])->transpose )' $VAR1 = bless( [ [ 1, 5 ], [ 2, 6 ], [ 3, 7 ] ], 'Math::Matrix' ); Which is more or less like mapcar, minus the blessing. [0] there is a mapcar method in the LISP module, but that's a horror show of a module [1] http://search.cpan.org/author/ULPFR/Math-Matrix-0.4/Matrix.pm#transpose
Re: Reordering Arrays.
On Wed, 13 Aug 2003, Mark Fowler wrote: > On Wed, 13 Aug 2003, Nicholas Clark wrote: > > > I'm not convinced that it's a great idea to sit it in a top level > > namespace. Is it about cartography? Or data manipulation? > > List::Maptastic? The function in question does matrix rotation -- that's math/data manipulation. Unless the other functionality is specifically about cartography, a more "usage-neutral" namespace might be better. IMO. -- Chris Devers[EMAIL PROTECTED]
Re: Reordering Arrays.
On Wed, Aug 13, 2003 at 06:02:59PM +0100, Sam Vilain wrote: > > If you nab mapcar[0] this is insanely simple > > Shortly to be released to CPAN as Maptastic, as soon as I figure out > the iteration semantics. > > Pre-release available at http://vilain.net/pm/Maptastic-0.99.tar.gz, > which has mapcar and mapcaru in it. Feedback most welcome. I'm not convinced that it's a great idea to sit it in a top level namespace. Is it about cartography? Or data manipulation? Apart from that reservation, go for it. Nicholas Clark
Reordering Arrays.
I have this: [ [ 1, 2, 3, ], [ 5, 6, 7, ], ] And I want this: [ [ 1, 5, ], [ 2, 6, ], [ 3, 7, ], ] How do I do that? I mean, I can write this code: sub reorder { my $new = []; foreach my $col_no (0..(@{ $_[0]->[0] } - 1)) { my $new_row = []; foreach my $row (@{ $_[0] }) { push @{ $new_row }, $row->[ $col_no ]; } push @{ $new }, $new_row; } return $new } But does anyone know a module that can do this? Any super fast cleverness that I don't want to even think about? Mark. -- #!/usr/bin/perl -T use strict; use warnings; print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
Re: Reordering Arrays.
If you nab mapcar[0] this is insanely simple Shortly to be released to CPAN as Maptastic, as soon as I figure out the iteration semantics. Pre-release available at http://vilain.net/pm/Maptastic-0.99.tar.gz, which has mapcar and mapcaru in it. Feedback most welcome. [0] http://www.perlmonks.org/index.pl?node_id=44763 -- Sam Vilain, [EMAIL PROTECTED] He who shits on the road will meet flies on his return. SOUTH AFRICAN SAYING
Re: Reordering Arrays.
If you nab mapcar[0] this is insanely simple use mapcar; use Data::Dumper; my $arrays= [ [1..3], [5..7] ]; my @reordered = mapcar { [EMAIL PROTECTED] } @$arrays; print Dumper([EMAIL PROTECTED]); __output__ $VAR1 = [ [ 1, 5 ], [ 2, 6 ], [ 3, 7 ] ]; Dan [0] http://www.perlmonks.org/index.pl?node_id=44763
Re: Reordering Arrays.
Mark Fowler wrote: But does anyone know a module that can do this? Any super fast cleverness that I don't want to even think about? Matrix rotation? Cf. PDL. -- Robin Berjon <[EMAIL PROTECTED]> Research Engineer, Expwayhttp://expway.fr/ 7FC0 6F5F D864 EFB8 08CE 8E74 58E6 D5DB 4889 2488
Re: Reordering Arrays.
On Wed, 13 Aug 2003, Nicholas Clark wrote: > I'm not convinced that it's a great idea to sit it in a top level namespace. > Is it about cartography? Or data manipulation? List::Maptastic? -- #!/usr/bin/perl -T use strict; use warnings; print q{Mark Fowler, [EMAIL PROTECTED], http://twoshortplanks.com/};
Re: Reordering Arrays.
Shevek ([EMAIL PROTECTED]) wrote: > On Mon, 11 Aug 2003, Mark Fowler wrote: > > > I have this: > > > >[ [ 1, 2, 3, ], > > [ 5, 6, 7, ], ] > > > > And I want this: > > > >[ [ 1, 5, ], > > [ 2, 6, ], > > [ 3, 7, ], ] Don't like the number 4 ?-) > > How do I do that? > > Use APL. Or Ruby 1.8: http://www.whytheluckystiff.net/articles/2003/08/04/rubyOneEightOh#Array-transpose
Re: Reordering Arrays.
On Wed, 13 Aug 2003, Nicholas Clark wrote: > I'm not convinced that it's a great idea to sit it in a top level > namespace. Is it about cartography? Or data manipulation? List::Maptastic? One function is for mapping hashes. So it would have to be Collection::Maptastic, or Collection::Map. But really, is anyone really going to use that namespace for anything? ;-) -- Sam Vilain, [EMAIL PROTECTED] Never invest your money in anything that eats or needs painting. BILLY ROSE