develooper Front page | perl.perl6.language | Postings from June 2009

Multi-d array transforms (was Re: Array rotate)

Thread Next
From:
yary
Date:
June 12, 2009 10:58
Subject:
Multi-d array transforms (was Re: Array rotate)
Message ID:
75cbfa570906121058x78765eddl10a8f5dd1b76755f@mail.gmail.com
Putting this in a new thread, as I'd like to discuss it separately
from refinements to Array.rotate

On Fri, Jun 12, 2009 at 10:11 AM, Jon Lang<dataweaver@gmail.com> wrote:
> With a multi-dimensional array, a number of transforms can be considered:
>
> * you can rearrange the elements along a given dimension (e.g., rotate
> and reverse).

Hmm, we have an Array.reverse already, which I think flattens a
multi-D array before reversing it. Maybe it could take an adverb (:by
?) to let you specify which dimension(s) to reverse, though I can't
think of anything satisfactory to specify an axis set. Or maybe
there's a "reflect" method on Array for reversing along an axis, or
axes.

> * you can rearrange the dimensions themselves (e.g., transpose).

Reflecting on 2 or more axes creates a transposition. Maybe it makes
sense to have a separate transpose, defined in terms of reflection.

There's still more reshaping possibilities, some of which is already easy eg

my @tall[2;8] = (1 .. 16);
# tall  (1,2; 3,4 ; 5,6; ... etc)
my @wide[8;2]=@tall;
# I think wide is (1 .. 8; 9 ..16)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About