Matrix transposition: Difference between revisions

Content added Content deleted
m (→‎Library gonum/matrix: library churn)
m (→‎{{header|Perl 6}}: mention shaped arrays)
Line 2,346: Line 2,346:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|rakudo|2015.10-46}}
{{Works with|rakudo|2018.03}}
Transposition can be done with the reduced zip metaoperator.
<lang perl6># Transposition can be done with the reduced zip meta-operator
# on list-of-lists data structures


<lang perl6>say [Z] (<A B C>,<D E F>,<G H I>)</lang>
say [Z] (<A B C D>, <E F G H>, <I J K L>);

# For native shaped arrays, a more traditional procedure of copying item-by-item
# Here the resulting matrix is also a native shaped array

my @a[3;4] =
[
[<A B C D>],
[<E F G H>],
[<I J K L>],
];

(my $n, my $m) = @a.shape;
my @b[$m;$n];
for ^$m X ^$n -> (\i, \j) {
@b[i;j] = @a[j;i];
}

say @b;</lang>


{{output}}
{{output}}


<pre>((A D G) (B E H) (C F I))</pre>
<pre>((A E I) (B F J) (C G K) (D H L))
[[A E I] [B F J] [C G K] [D H L]]</pre>


=={{header|Phix}}==
=={{header|Phix}}==