2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1 +1,2 @@
[[wp:Transpose|Transpose]] an arbitrarily sized rectangular [[wp:Matrix (mathematics)|Matrix]].
<br><br>

View file

@ -0,0 +1,39 @@
...
KN EQU 3
KM EQU 5
N DC AL2(KN)
M DC AL2(KM)
A DS (KN*KM)F matrix a(n,m)
B DS (KM*KN)F matrix b(m,n)
...
* b(j,i)=a(i,j)
* transposition using Horner's formula
LA R4,0 i,from 1
LA R7,KN to n
LA R6,1 step 1
LOOPI BXH R4,R6,ELOOPI do i=1 to n
LA R5,0 j,from 1
LA R9,KM to m
LA R8,1 step 1
LOOPJ BXH R5,R8,ELOOPJ do j=1 to m
LR R1,R4 i
BCTR R1,0 i-1
MH R1,M (i-1)*m
LR R2,R5 j
BCTR R2,0 j-1
AR R1,R2 r1=(i-1)*m+(j-1)
SLA R1,2 r1=((i-1)*m+(j-1))*itemlen
L R0,A(R1) r0=a(i,j)
LR R1,R5 j
BCTR R1,0 j-1
MH R1,N (j-1)*n
LR R2,R4 i
BCTR R2,0 i-1
AR R1,R2 r1=(j-1)*n+(i-1)
SLA R1,2 r1=((j-1)*n+(i-1))*itemlen
ST R0,B(R1) b(j,i)=r0
B LOOPJ next j
ELOOPJ EQU * out of loop j
B LOOPI next i
ELOOPI EQU * out of loop i
...

View file

@ -0,0 +1,21 @@
on run
transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
--> {{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}
end run
on transpose(xss)
set lstTrans to {}
repeat with iCol from 1 to length of item 1 of xss
set lstCol to {}
repeat with iRow from 1 to length of xss
set end of lstCol to item iCol of item iRow of xss
end repeat
set end of lstTrans to lstCol
end repeat
return lstTrans
end transpose

View file

@ -0,0 +1,52 @@
-- transpose :: [[a]] -> [[a]]
on transpose(xss)
script column
on lambda(_, iCol)
script row
on lambda(xs)
item iCol of xs
end lambda
end script
map(row, xss)
end lambda
end script
map(column, item 1 of xss)
end transpose
-- TEST
on run
transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
--> {{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}
end run
-- GENERIC LIBRARY FUNCTIONS
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to lambda(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property lambda : f
end script
end if
end mReturn

View file

@ -0,0 +1 @@
{{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}

View file

@ -8,4 +8,4 @@
(defmethod matrix-transpose clojure.lang.PersistentVector
[mtx]
(vec (apply map vector mtx)))
(apply mapv vector mtx))

View file

@ -0,0 +1,17 @@
class Matrix {
static function main() {
var m = [ [1, 1, 1, 1],
[2, 4, 8, 16],
[3, 9, 27, 81],
[4, 16, 64, 256],
[5, 25, 125, 625] ];
var t = [ for (i in 0...m[0].length)
[ for (j in 0...m.length) 0 ] ];
for(i in 0...m.length)
for(j in 0...m[0].length)
t[j][i] = m[i][j];
for(aa in [m, t])
for(a in aa) Sys.println(a);
}
}

View file

@ -1,12 +1,16 @@
transpose = function(a) {
return a[0].map(function(x,i) {
return a.map(function(y,k) {
return y[i];
});
});
}
(function () {
'use strict';
A = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
function transpose(lst) {
return lst[0].map(function (_, iCol) {
return lst.map(function (row) {
return row[iCol];
})
});
}
JSON.stringify(transpose(A));
"[[1,4,7,10],[2,5,8,11],[3,6,9,12]]"
return transpose(
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
);
})();

View file

@ -0,0 +1,16 @@
(() => {
'use strict';
// transpose :: [[a]] -> [[a]]
let transpose = xs =>
xs[0].map((_, iCol) => xs.map((row) => row[iCol]));
// TEST
return transpose([
[1, 2],
[3, 4],
[5, 6]
]);
})();

View file

@ -0,0 +1 @@
[[1, 3, 5], [2, 4, 6]]

View file

@ -7,12 +7,10 @@ sub transpose(@m)
# creates a random matrix
my @a;
for (^10).pick X (^10).pick -> ($x, $y) { @a[$x][$y] = (^100).pick; }
say "original: ";
.perl.say for @a;
for ^5 X ^5 -> ($x, $y) { @a[$x][$y] = ('a'..'z').pick; }
say "original:";
.gist.say for @a;
my @b = transpose(@a);
say "transposed: ";
.perl.say for @b;
say "transposed:";
.gist.say for @b;

View file

@ -0,0 +1,58 @@
function transpose($a) {
$arr = @()
if($a) {
$n = $a.count - 1
if(0 -lt $n) {
$m = ($a | foreach {$_.count} | measure-object -Minimum).Minimum - 1
if( 0 -le $m) {
if (0 -lt $m) {
$arr =@(0)*($m+1)
foreach($i in 0..$m) {
$arr[$i] = foreach($j in 0..$n) {@($a[$j][$i])}
}
} else {$arr = foreach($row in $a) {$row[0]}}
}
} else {$arr = $a}
}
$arr
}
function show($a) {
if($a) {
0..($a.Count - 1) | foreach{ if($a[$_]){"$($a[$_])"}else{""} }
}
}
$a = @(@(2, 0, 7, 8),@(3, 5, 9, 1),@(4, 1, 6, 3))
"`$a ="
show $a
""
"transpose `$a ="
show (transpose $a)
""
$a = @(1)
"`$a ="
show $a
""
"transpose `$a ="
show (transpose $a)
""
"`$a ="
$a = @(1,2,3)
show $a
""
"transpose `$a ="
"$(transpose $a)"
""
"`$a ="
$a = @(@(4,7,8),@(1),@(2,3))
show $a
""
"transpose `$a ="
"$(transpose $a)"
""
"`$a ="
$a = @(@(4,7,8),@(1,5,9,0),@(2,3))
show $a
""
"transpose `$a ="
show (transpose $a)

View file

@ -1,5 +1,5 @@
function transpose($a) {
if($a.Count -gt 0) {
if($a) {
$n = $a.Count - 1
foreach($i in 0..$n) {
$j = 0
@ -12,9 +12,8 @@ function transpose($a) {
$a
}
function show($a) {
if($a.Count -gt 0) {
$n = $a.Count - 1
0..$n | foreach{ "$($a[$_][0..$n])" }
if($a) {
0..($a.Count - 1) | foreach{ if($a[$_]){"$($a[$_])"}else{""} }
}
}
$a = @(@(2, 4, 7),@(3, 5, 9),@(4, 1, 6))

View file

@ -1,32 +1,28 @@
/*REXX program transposes a matrix, shows before and after matrixes. */
x. =
x.1 = 1.02 2.03 3.04 4.05 5.06 6.07 7.07
x.2 = 111 2222 33333 444444 5555555 66666666 777777777
/*REXX program transposes a matrix, and displays the before and after matrices. */
x.=; x.1 = 1.02 2.03 3.04 4.05 5.06 6.07 7.07
x.2 = 111 2222 33333 444444 5555555 66666666 777777777
do r=1 while x.r\=='' /*build the "A" matric from X. numbers */
do c=1 while x.r\==''
parse var x.r a.r.c x.r
end /*c*/
end /*r*/
rows = r-1; cols = c-1
L=0 /*L is the maximum width element value.*/
do i=1 for rows
do j=1 for cols
b.j.i = a.i.j; L=max(L,length(b.j.i))
end /*j*/
end /*i*/
do r=1 while x.r\=='' /*build matrix A from matrix X.*/
do c=1 while x.r\==''
parse var x.r a.r.c x.r
end /*c*/
end /*r*/
rows=r-1; cols=c-1 /*adjust for DO loop indices. */
L=0 /*L is max width element value. */
do i=1 for rows
do j=1 for cols
b.j.i=a.i.j; L=max( L, length(b.j.i) )
end /*j*/
end /*i*/
call showMat 'A', rows, cols
call showMat 'B', cols, rows
exit /*stick a fork in it, we're done.*/
/*─────────────────────────────────────SHOWMAT subroutine───────────────*/
showMat: parse arg mat,rows,cols; say
say center(mat 'matrix', cols*(L+1) +4, "")
do r=1 for rows; _=
do c=1 for cols; _ = _ right(value(mat'.'r'.'c), L)
end /*c*/
say _
end /*r*/
return
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: parse arg mat,rows,cols; say; say center(mat 'matrix', cols*(L+1)+4, "")
do r=1 for rows; _=
do c=1 for cols; _=_ right(value(mat'.'r"."c), L)
end /*c*/
say _
end /*r*/
return