June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -3,15 +3,15 @@ package main
import (
"fmt"
"github.com/gonum/matrix/mat64"
"gonum.org/v1/gonum/mat"
)
func main() {
m := mat64.NewDense(2, 3, []float64{
m := mat.NewDense(2, 3, []float64{
1, 2, 3,
4, 5, 6,
})
fmt.Println(mat64.Formatted(m))
fmt.Println(mat.Formatted(m))
fmt.Println()
fmt.Println(mat64.Formatted(m.T()))
fmt.Println(mat.Formatted(m.T()))
}

View file

@ -2,11 +2,9 @@
'use strict';
// transpose :: [[a]] -> [[a]]
let transpose = xs =>
const transpose = xs =>
xs[0].map((_, iCol) => xs.map((row) => row[iCol]));
// TEST
return transpose([
[1, 2],

View file

@ -1 +1,22 @@
say [Z] (<A B C>,<D E F>,<G H I>)
# Transposition can be done with the reduced zip meta-operator
# on list-of-lists data structures
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;

View file

@ -0,0 +1,25 @@
/*REXX program transposes any sized rectangular matrix, displays before & after matrices*/
@.=; @.1 = 1.02 2.03 3.04 4.05 5.06 6.07 7.08
@.2 = 111 2222 33333 444444 5555555 66666666 777777777
w=0
do row=1 while @.row\==''
do col=1 until @.row==''; parse var @.row A.row.col @.row
w=max(w, length(A.row.col) ) /*max width for elements*/
end /*col*/ /*(used to align ouput).*/
end /*row*/ /* [↑] build matrix A from the @ lists*/
row= row-1 /*adjust for DO loop index increment.*/
do j=1 for row /*process each row of the matrix.*/
do k=1 for col /* " " column " " " */
B.k.j= A.j.k /*transpose the A matrix (into B). */
end /*k*/
end /*j*/
call showMat 'A', row, col /*display the A matrix to terminal.*/
call showMat 'B', col, row /* " " B " " " */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: arg mat,rows,cols; say; say center( mat 'matrix', (w+1)*cols +4, "")
do r=1 for rows; _= /*newLine*/
do c=1 for cols; _=_ right( value( mat'.'r"."c), w) /*append.*/
end /*c*/
say _ /*1 line.*/
end /*r*/; return

View file

@ -0,0 +1,16 @@
. mat a=1,2,3\4,5,6
. mat b=a'
. mat list a
a[2,3]
c1 c2 c3
r1 1 2 3
r2 4 5 6
. mat list b
b[3,2]
r1 r2
c1 1 4
c2 2 5
c3 3 6

View file

@ -0,0 +1,21 @@
: a=1,1i
: a
1 2
+-----------+
1 | 1 1i |
+-----------+
: a'
1
+-------+
1 | 1 |
2 | -1i |
+-------+
: transposeonly(a)
1
+------+
1 | 1 |
2 | 1i |
+------+