Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
auto transpose(T)(in T[][] m) /*pure nothrow*/ {
|
||||
return iota(m[0].length).map!(i => transversal(m, i))();
|
||||
return m[0].length.iota.map!(i => m.transversal(i));
|
||||
}
|
||||
|
||||
void main() {
|
||||
enum M = [[10, 11, 12, 13],
|
||||
[14, 15, 16, 17],
|
||||
[18, 19, 20, 21]];
|
||||
/*immutable*/ auto T = transpose(M);
|
||||
immutable M = [[10, 11, 12, 13],
|
||||
[14, 15, 16, 17],
|
||||
[18, 19, 20, 21]];
|
||||
/*immutable*/ auto T = M.transpose;
|
||||
writefln("%(%(%2d %)\n%)", T);
|
||||
}
|
||||
|
|
|
|||
10
Task/Matrix-transposition/Julia/matrix-transposition.julia
Normal file
10
Task/Matrix-transposition/Julia/matrix-transposition.julia
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
julia> [1 2 3 ; 4 5 6] # a 2x3 matrix
|
||||
2x3 Array{Int64,2}:
|
||||
1 2 3
|
||||
4 5 6
|
||||
|
||||
julia> [1 2 3 ; 4 5 6]' # note the quote
|
||||
3x2 Array{Int64,2}:
|
||||
1 4
|
||||
2 5
|
||||
3 6
|
||||
23
Task/Matrix-transposition/Lua/matrix-transposition-1.lua
Normal file
23
Task/Matrix-transposition/Lua/matrix-transposition-1.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
function Transpose( m )
|
||||
local res = {}
|
||||
|
||||
for i = 1, #m[1] do
|
||||
res[i] = {}
|
||||
for j = 1, #m do
|
||||
res[i][j] = m[j][i]
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- a test for Transpose(m)
|
||||
mat = { { 1, 2, 3 }, { 4, 5, 6 } }
|
||||
erg = Transpose( mat )
|
||||
for i = 1, #erg do
|
||||
for j = 1, #erg[1] do
|
||||
io.write( erg[i][j] )
|
||||
io.write( " " )
|
||||
end
|
||||
io.write( "\n" )
|
||||
end
|
||||
27
Task/Matrix-transposition/Lua/matrix-transposition-2.lua
Normal file
27
Task/Matrix-transposition/Lua/matrix-transposition-2.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
function map(f, a)
|
||||
local b = {}
|
||||
for k,v in ipairs(a) do b[k] = f(v) end
|
||||
return b
|
||||
end
|
||||
|
||||
function mapn(f, ...)
|
||||
local c = {}
|
||||
local k = 1
|
||||
local aarg = {...}
|
||||
local n = table.getn(aarg)
|
||||
while true do
|
||||
local a = map(function(b) return b[k] end, aarg)
|
||||
if table.getn(a) < n then return c end
|
||||
c[k] = f(unpack(a))
|
||||
k = k + 1
|
||||
end
|
||||
end
|
||||
|
||||
function apply(f1, f2, a)
|
||||
return f1(f2, unpack(a))
|
||||
end
|
||||
|
||||
xy = {{1,2,3,4},{1,2,3,4},{1,2,3,4}}
|
||||
yx = apply(mapn, function(...) return {...} end, xy)
|
||||
print(table.concat(map(function(a) return table.concat(a,",") end, xy), "\n"),"\n")
|
||||
print(table.concat(map(function(a) return table.concat(a,",") end, yx), "\n"))
|
||||
13
Task/Matrix-transposition/MATLAB/matrix-transposition-1.m
Normal file
13
Task/Matrix-transposition/MATLAB/matrix-transposition-1.m
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>> transpose([1 2;3 4])
|
||||
|
||||
ans =
|
||||
|
||||
1 3
|
||||
2 4
|
||||
|
||||
>> [1 2;3 4].'
|
||||
|
||||
ans =
|
||||
|
||||
1 3
|
||||
2 4
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
B=size(A); %In this code, we assume that a previous matrix "A" has already been inputted.
|
||||
for j=1:B(1)
|
||||
for i=1:B(2)
|
||||
C(i,j)=A(j,i);
|
||||
end %The transposed A-matrix should be C
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
xy = {{1,2,3,4},{1,2,3,4},{1,2,3,4}}
|
||||
yx = feval(@(x) cellfun(@(varargin)[varargin],x{:},'un',0), xy)
|
||||
|
|
@ -1,32 +1,31 @@
|
|||
/*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'
|
||||
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*/
|
||||
end /*c*/
|
||||
end /*r*/
|
||||
|
||||
rows=r-1; cols=c-1
|
||||
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*/
|
||||
end /*j*/
|
||||
end /*i*/
|
||||
|
||||
call showMat 'A',rows,cols
|
||||
call showMat 'B',cols,rows
|
||||
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, "─")
|
||||
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)
|
||||
do c=1 for cols; _ = _ right(value(mat'.'r'.'c), L)
|
||||
end /*c*/
|
||||
say _
|
||||
end /*r*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue