@@ -839,19 +839,28 @@ sub twiddle {
839839
840840=head3 C<slice >
841841
842- Produce the degree (n-1) Matrix defined by a given index and value for that index. If n is 1,
843- this produces a Real/Complex/Fraction.
842+ Produce the degree (n-1) Matrix defined by a given index (the first, second, ..., nth) and a
843+ value for that index along that dimension. If n is 1, this produces a Real/Complex/Fraction.
844844
845845Usage:
846846
847847 $A = Matrix([ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ] ]);
848- $A->slice(1, 2) # will be same as Matrix([5, 6, 7, 8])
849- $A->slice(2, 3) # will be same as Matrix([3, 7, 11])
848+ $A->slice(1, 2)
849+ # Index 1 identifies the 1st, 2nd, or 3rd row above, and with value 2 we get the second one:
850+ # Matrix([5, 6, 7, 8])
850851
851852 $B = Matrix([ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ]);
852- $B->slice(1, 2) # will be same as Matrix([ [ 5, 6 ], [ 7, 8 ] ])
853- $B->slice(2, 1) # will be same as Matrix([ [ 1, 2 ], [ 5, 6 ] ])
854- $B->slice(3, 1) # will be same as Matrix([ [ 1, 3 ], [ 5, 7 ] ])
853+ $B->slice(1, 2)
854+ # Index 1 identifies the two arrays at depth 1, and with value 2 we get the second one:
855+ # Matrix([ [ 5, 6 ], [ 7, 8 ] ])
856+ $B->slice(2, 1)
857+ # Here we take all entries from $B where the 2nd index is 1: the 1 at position (1,1,1),
858+ # the 2 at position (1,1,2), the 5 at position (2,1,1), and the 6 at position (2,1,2):
859+ # Matrix([ [ 1, 2 ], [ 5, 6 ] ])
860+ $B->slice(3, 1)
861+ # Here we take all entries from $B where the 3rd index is 1: the 1 at position (1,1,1),
862+ # the 3 at position (1,2,1), the 5 at position (2,1,1), and the 7 at position (2,2,1):
863+ # Matrix([ [ 1, 3 ], [ 5, 7 ] ])
855864
856865=cut
857866
@@ -885,14 +894,41 @@ specified, the default is the usual transposition of the last two indices.
885894
886895Usage:
887896
888- $A = Matrix([ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ] ]);
889- $A->transpose # will be [ [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7, 11 ], [ 4, 8, 12 ] ]
890-
891- $B = Matrix([ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ]);
892- $B->transpose([1, 2, 3]) # will be [ [ [ 1, 3 ], [ 5, 7 ] ], [ [2 , 4 ], [ 6, 8 ] ] ]
893-
894- $C = Matrix([ [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], [ [ [ 9, A ], [ B, C ] ], [ [ D, E ], [ F, 0 ] ] ] ]);
895- $C->transpose([ [ 1, 2], [3, 4] ]) # will be [ [ [ [ 1, 3 ], [ 2, 4 ] ], [ [ 9, B ], [ A, C ] ] ], [ [ [ 5, 7 ], [ 6, 8 ] ], [ [ D, F ], [ E, 0 ] ] ]
897+ $A = Matrix([
898+ [ 1, 2, 3, 4 ],
899+ [ 5, 6, 7, 8 ],
900+ [ 9, 10, 11, 12 ]
901+ ]);
902+ $A->transpose
903+ # will be
904+ # [
905+ # [ 1, 5, 9 ],
906+ # [ 2, 6, 10 ],
907+ # [ 3, 7, 11 ],
908+ # [ 4, 8, 12 ]
909+ # ]
910+
911+ $B = Matrix([
912+ [ [ 1, 2 ], [ 3, 4 ] ],
913+ [ [ 5, 6 ], [ 7, 8 ] ]
914+ ]);
915+ $B->transpose([1, 2, 3])
916+ # will be
917+ # [
918+ # [ [ 1, 3 ], [ 5, 7 ] ],
919+ # [ [ 2, 4 ], [ 6, 8 ] ]
920+ # ]
921+
922+ $C = Matrix([
923+ [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ],
924+ [ [ [ 9, 10 ], [ 11, 12 ] ], [ [ 13, 14 ], [ 15, 16 ] ] ]
925+ ]);
926+ $C->transpose([ [ 1, 2], [3, 4] ])
927+ # will be
928+ # [
929+ # [ [ [ 1, 3 ], [ 2, 4 ] ], [ [ 9, 11 ], [ 10, 12 ] ] ],
930+ # [ [ [ 5, 7 ], [ 6, 8 ] ], [ [ 13, 15 ], [ 14, 16 ] ] ]
931+ # ]
896932=cut
897933
898934sub transpose {
0 commit comments