戻る |
全行番号の列挙 |
|
Public Function a_rows(ByRef matrix As Variant, Optional ByRef dummy As Variant) As
Variant |
|
|
|
Public Function p_a_rows( |
|
|
|
printM a_rows(makeM(8,5)) |
|
0 1
2 3 4
5 6 7 |
|
m = a_rows(repeat(3,
11)) |
|
printM a_rows(m)
' 1次元配列にも対応 |
|
0 1
2 3 4
5 6 7
8 9 10 |
|
changeLBound m, -3 |
|
printM a_rows(m) |
|
-3 -2 -1 0
1 2 3
4 5 6
7 |
|
|
全列番号の列挙 |
|
Public Function a_cols(ByRef matrix As Variant, Optional ByRef dummy As Variant) As
Variant |
|
Public Function p_a_cols( |
|
|
|
printM a_cols(makeM(8,5)) |
|
0 1
2 3 4 |
|
|
N個の値を並べる |
戻る |
Public Function repeat(ByRef v As Variant, ByRef n As Variant) As Variant |
|
Public Function p_repeat( |
|
|
|
printM repeat(3,
8) |
|
3 3
3 3 3
3 3 3 |
|
|
|
|
fromからtoまでの自然数を並べたベクトルを返す |
|
両端入り。from <= to では昇順、from > to では逆順 |
|
Public Function iota(ByRef from_i As Variant, ByRef to_i As Variant) As Variant |
|
|
|
Public Function p_iota( |
|
|
|
printM iota(3,
9) |
|
3 4
5 6 7
8 9 |
|
printM iota(9,
3) |
|
9 8
7 6 5
4 3 |
|
|
自然数列 [from, to] |
|
Public Function a__a(ByRef from_i As Variant, ByRef to_i As Variant) As Variant |
|
|
|
Public Function p_a__a( |
|
|
|
printM a__a(7,
11) |
|
7 8
9 10 11 |
|
|
自然数列 [from, to) |
戻る |
Public Function a__o(ByRef from_i As Variant, ByRef to_i As Variant) As Variant |
|
|
|
Public Function p_a__o( |
|
|
|
printM a__o(3,
9) |
|
3 4
5 6 7
8 |
|
printM a__o(3,
3) |
|
#Empty Matrix# |
|
|
自然数列 (from, to] |
|
Public Function o__a(ByRef from_i As Variant, ByRef to_i As Variant) As Variant |
|
|
|
Public Function p_o__a( |
|
|
|
printM o__a(1,
6) |
|
2 3
4 5 6 |
|
|
自然数列 (from, to) |
|
Public Function o__o(ByRef from_i As Variant, ByRef to_i As Variant) As Variant |
戻る |
|
|
Public Function p_o__o( |
|
|
|
printM o__o(1,
6) |
|
2 3
4 5 |
|
|
ベクトルの最初のN個 |
|
Public Function headN(ByRef vec As Variant, ByRef n As Variant) As Variant |
|
|
|
Public Function p_headN( |
|
|
|
printM headN(iota(1,
10), 4) |
|
1 2
3 4
← 前から4個 |
|
printM headN(iota(1,
10), -4) |
|
1 2
3 4 5
6
← 後ろ4個をカット |
|
|
ベクトルの最後のN個 |
|
Public Function tailN(ByRef vec As Variant, ByRef n As Variant) As Variant |
|
|
戻る |
Public Function p_tailN( |
|
|
|
printM tailN(iota(1,
10), 4) |
|
7 8
9 10
← 後ろから4個 |
|
printM tailN(iota(1,
10), -4) |
|
5 6
7 8 9
10
← 前4個をカット |
|
|
スカラー、配列の1次元配列化 |
|
Public Function vector(ByRef data As Variant, Optional ByRef order As Variant) As
Variant |
|
|
|
m = makeM(3,3,iota(1, 9)) |
|
printM m |
|
1 2
3 |
|
4 5
6 |
|
7 8
9 |
|
printM vector(m)
' C言語オーダー |
|
1 2
3 4 5
6 7 8
9 |
|
printM vector(m, False)
' VBオーダー |
|
1 4
7 2 5
8 3 6
9 |
|
|
ベクトルを逆順に並べる |
|
Public Function reverse(ByRef vec As Variant) As Variant |
|
|
|
printM reverse(iota(2,9)) |
|
9 8
7 6 5
4 3 2 |
|
|
1次元配列の回転 |
|
[0,1,2,3,4,5] -> [1,2,3,4,5,0] (r=1) |
|
[0,1,2,3,4,5] -> [5,0,1,2,3,4] (r=-1) |
戻る |
Sub rotate(ByRef
vec As Variant, ByVal shift As Long) |
|
|
|
m = iota(1, 9) |
|
rotate m, 1 |
|
printM m |
|
2 3
4 5 6
7 8 9
1 |
|
m = iota(1, 9) |
|
rotate m, -1 |
|
printM m |
|
9 1
2 3 4
5 6 7
8 |
|
|
|
|
1次元配列を回転した配列 |
|
Function rotation(ByRef vec As Variant, ByRef shift As Variant) As Variant |
|
|
|
Function p_rotation( |
|
|
|
m = iota(1, 9) |
|
a = rotation(m,
1) |
|
printM a |
|
2 3
4 5 6
7 8 9
1 |
|
printM m |
戻る |
1 2
3 4 5
6 7 8
9 |
|
|
|
|
rotationしてmoveして返す |
|
Function rotate_move(ByRef vec As Variant, ByRef shift As Variant) As Variant |
|
|
|
Function p_rotate_move( |
|
|
|
m = iota(1, 9) |
|
a = rotate_move(m,
1) |
|
printM a |
|
2 3
4 5 6
7 8 9
1 |
|
?IsEmpty(m) |
|
True
← mはaにmoveされて消えた |
|
|
|
|
特定行の取得 |
|
Public Function selectRow(ByRef matrix As Variant, ByRef i As Variant) As Variant |
|
|
|
Public Function p_selectRow( |
|
|
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
printM selectRow(m, 1) |
|
5 6
7 8 |
戻る |
|
|
|
特定列の取得 |
|
Public Function selectCol(ByRef matrix As Variant, ByRef j As Variant) As Variant |
|
|
|
Public Function p_selectCol( |
|
|
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
printM selectCol(m, 2) |
|
3 7
11 |
|
|
配列の作成 |
|
makeM(6, 3) => 6行(0,1,2,3,4,5) x 3列(0,1,2) |
|
Public Function makeM(ByVal R As Long, Optional ByVal c As Variant, Optional ByRef
data As Variant) As Variant |
|
|
|
printM makeM(2,
3) |
|
← 要素はEmpty |
|
|
|
printM makeM(3,
4, iota(1,12)) |
|
1 2 3 4 |
|
5 6 7 8 |
戻る |
9 10 11 12 |
|
|
配列をデータで埋める |
|
Public Sub fillM(ByRef matrix As Variant, ByRef data As Variant) |
|
|
|
?seed_engine() |
|
2141818439 |
|
m = makeM(3, 8) |
|
fillM m,
uniform_int_dist(24, 1,10) |
|
printM m |
|
1 7
9 2 5
1 9 6 |
|
5 7
3 1 4
1 10 7 |
|
6 6
6 9 6
9 9 6 |
|
|
配列をデータで埋めてmoveして返す |
|
Public Function fillM_move(ByRef matrix As Variant, ByRef data As Variant) As Variant |
|
|
|
m = makeM(3, 8) |
|
a = fillM_move(m,
uniform_int_dist(24, 1,10)) |
|
printM a |
|
10 10 9
8 8 9 10 2 |
|
6 7 9
2 8 10 5 6 |
戻る |
7 10 5
6 4 1 1 8 |
|
?IsEmpty(m) |
|
True |
|
|
配列の特定行をデータで埋める |
|
Public Sub fillRow(ByRef matrix As Variant, ByVal i As Long, ByRef data As
Variant) |
|
|
|
m = makeM(3, 4, iota(1,12)) |
|
fillRow m, 1, Array(100,101,102,103) |
|
printM m |
|
1 2 3 4 |
|
100 101 102 103 |
|
9 10 11 12 |
|
|
配列の特定行をデータで埋めてmoveして返す |
|
Public Function fillRow_move(ByRef matrix As Variant, ByVal i As Long, ByRef data As
Variant) As Variant |
|
|
|
m = makeM(3, 400, iota(1,1200)) |
|
printM foldl1(p_plus, fillRow_move(m, 1, iota(100001, 100401)), 2) |
|
80200 40080200 400200 |
戻る |
?IsEmpty(m) |
|
True |
|
|
|
|
配列の特定列をデータで埋める |
|
Public Sub fillCol(ByRef matrix As Variant, ByVal j As Long, ByRef data As
Variant) |
|
|
|
m = makeM(3, 4, iota(1,12)) |
|
fillCol m, 1, Array(100,101,102) |
|
printM m |
|
1 100 3 4 |
|
5 101 7 8 |
|
9 102 11 12 |
|
|
配列の特定列をデータで埋めてmoveして返す |
|
Public Function fillCol_move(ByRef matrix As Variant, ByVal j As Long, ByRef data As
Variant) As Variant |
|
|
|
|
1次元配列を他の1次元配列の繰り返しで埋める(回数指定可) |
|
Sub fillPattern(ByRef
vec As Variant, ByRef pattern As Variant, Optional ByVal counter As Long =
-1) |
|
|
|
m = makeM(10) |
|
fillPattern
m, Array(7, 9, "www") |
|
printM m |
|
7 9
www 7 9
www 7 9
www 7 |
戻る |
|
|
|
1次元配列を他の1次元配列の繰り返しで埋めてmoveして返す |
|
Public Function fillPattern_move(ByRef vec As Variant, ByRef pattern As Variant, _ |
|
Optional ByVal counter As Long = -1) As Variant |
|
|
'1次元配列の部分配列を作成する |
|
Public Function subV(ByRef vec As Variant, ByRef index As Variant) As Variant |
|
|
|
Public Function p_subV( |
|
|
|
m = iota(1, 1000) |
|
printM subV(m,
Array(9, 32, 1, 555, 222)) |
|
10 33 2
556 223 |
|
|
|
|
1次元配列の部分配列を作成する(範囲外のインデックスに対してEmptyが入る) |
|
Public Function subV_if(ByRef vec As Variant, ByRef index As Variant) As Variant |
|
|
|
Public Function p_subV_if( |
|
|
戻る |
m = iota(1,1000) |
|
printM subV_if(m, Array(9, 32, 1, -1, 222))
' -1 は [LBound, UBound] 範囲外 |
|
10 33 2 223 |
|
printM subV_if(m, Array(9, 32, 1, Null, 222))
' Null は常に範囲外 |
|
10 33 2 223 |
|
|
配列の部分配列を作成する |
|
Public Function subM(ByRef matrix As Variant, _ |
|
Optional ByRef rows As Variant, _ |
|
Optional ByRef cols As Variant) As Variant |
|
|
|
m = makeM(100, 100, iota(1,10000)) |
|
printM subM(m, Array(6, 99),
Array(9, 32, 2))
← 行と列を指定 |
|
610 633 603 |
|
9910 9933 9903 |
|
m = makeM(7, 7, iota(1, 49)) |
|
printM subM(m, Array(3, 6))
← 列指定を省略 |
|
22 23 24 25 26 27 28 |
|
43 44 45 46 47 48 49 |
|
printM subM(m, , Array(3, 6))
← 行指定を省略 |
|
4 7 |
|
11 14 |
戻る |
18 21 |
|
25 28 |
|
32 35 |
|
39 42 |
|
46 49 |
|
|
配列の部分配列を作成する(範囲外のインデックスに対してEmptyが入る) |
|
Public Function subM_if(ByRef matrix As Variant, _ |
|
Optional ByRef rows As Variant, _ |
|
Optional ByRef cols As Variant) As Variant |
|
|
ベクトル・配列の(行の)フィルタリング |
|
Flgは 0/1 |
|
Public Function filterR(ByRef data As Variant, ByRef flg As Variant) As Variant |
|
|
|
Public Function p_filterR( |
|
|
|
m = iota(1, 7) |
|
printM filterR(m, Array(1, 0, 1, 0, 1, 0,
1)) |
|
1 3
5 7 |
|
m = makeM(4, 4, iota(1, 16)) |
戻る |
printM filterR(m, Array(1, 0, 1, 0)) |
|
1 2 3 4 |
|
9 10 11 12 |
|
|
|
|
配列の(列の)フィルタリング |
|
Flgは 0/1 |
|
Public Function filterC(ByRef data As Variant, ByRef flg As Variant) As Variant |
|
|
|
Public Function p_filterC( |
|
|
|
m = makeM(4, 4, iota(1, 16)) |
|
printM filterC(m,
Array(1,0,1,0)) |
|
1 3 |
|
5 7 |
|
9 11 |
|
13 15 |
|
|
ベクトルを結合 |
|
Function catV(ByRef
v1 As Variant, ByRef v2 As Variant) As Variant |
|
|
戻る |
Function p_catV( |
|
|
|
printM catV(iota(1, 7), iota(98, 103)) |
|
1 2
3 4 5
6 7 98 99 100 101 102 103 |
|
|
ベクトルを結合(引数をmove) |
|
Function catV_move(ByRef v1 As Variant, ByRef v2 As Variant) As Variant |
|
|
|
Function p_catV_move( |
|
|
|
printM catV_move(iota(1, 7), iota(98,
103)) |
|
1 2
3 4 5
6 7 98 99 100 101 102 103 |
|
|
ベクトルを結合(可変長引数) |
|
Function catVs(ParamArray
vectors() As Variant) As Variant |
|
|
|
printM catVs(iota(1, 3),
Array("A", "D"), iota(98, 100), Array("www.",
"com")) |
|
1 2
3 A D
98 99 100 www. com |
|
|
ベクトルを結合(可変長引数:引数をmove) |
|
Function catVs_move(ParamArray vectors() As Variant) As Variant |
|
|
|
printM catVs_move(iota(1, 3),
Array("A", "D"), iota(98, 100), Array("www.",
"com")) |
|
1 2
3 A D
98 99 100 www. com |
戻る |
|
|
|
行方向に結合 |
|
Function catR(ByRef
matrix1 As Variant, ByRef matrix2 As Variant) As Variant |
|
|
|
Function p_catR( |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM catR(m, iota(1, 4)) |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
1 2 3 4 |
|
長さが揃っていないとダメ |
|
揃っていれば1次元と2次元が混在していても可 |
|
|
列方向に結合 |
|
Function catC(ByRef
matrix1 As Variant, ByRef matrix2 As Variant) As Variant |
|
|
戻る |
Function p_catC( |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM catC(m, iota(1,3)) |
|
1 2 3 4 1 |
|
5 6 7 8 2 |
|
9 10 11 12 3 |
|
長さが揃っていないとダメ |
|
揃っていれば1次元と2次元が混在していても可 |
|
|
配列の行/列の転置 |
|
Function transpose(ByRef matrix As Variant) As Variant |
|
|
|
m = makeM(3, 4, iota(1,12)) |
|
printM transpose(m) |
|
1 5 9 |
|
2 6
10 |
|
3 7
11 |
|
4 8
12 |
|
printM transpose(iota(1, 3))
←1次元配列は縦になる |
|
1 |
|
2 |
|
3 |
|
|
|
戻る |
ふたつの配列の対応する要素どうしをmakePairしてジャグ配列を作る |
|
Public Function zip(ByRef a As Variant, ByRef b As Variant) As Variant |
|
|
|
Function p_zip( |
|
|
|
m = zip(iota(1,
4), iota(101, 104)) |
|
printM m |
|
[0] [1] [2] [3]
← ジャグ配列 |
|
printM m(0) |
|
1 101 |
|
printM m(1) |
|
2 102 |
|
printM m(2) |
|
3 103 |
|
printM_ m
← printM ではなく printM_ |
|
|
|
2 102 |
|
3 103 |
|
4 104 |
|
|
複数の1次元配列をzip |
|
Function cross_zip(ByRef vectors As Variant) As Variant |
|
|
戻る |
a=Array(iota(1, 4), iota(101, 104), iota(8, 11)) |
|
printM_ a |
|
1 2
3 4 |
|
101 102 103 104 |
|
8 9
10 11 |
|
|
|
b = cross_zip(a) |
|
printM_ b |
|
1 101 8 |
|
2 102 9 |
|
3 103 10 |
|
4 104 11 |
|
|
|
c = cross_zip(b)
' cross_zip を偶数回適用するtと元に戻る |
|
printM_ c |
|
1 2
3 4 |
|
101 102 103 104 |
|
8 9
10 11 |
|
4 104 11 |
|
|
2次元配列の各行ベクトルをzipVs |
戻る |
Function zipR(ByRef
m As Variant, Optional ByRef target As Variant) As Variant |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
|
|
r = zipR(m) |
|
printM r |
|
[0] [1] [2] [3] |
|
printM_ r |
|
|
|
2 6
10 |
|
3 7
11 |
|
4 8
12 |
|
|
|
r = zipR(m, Array(0, 2))
← 対象行を指定 |
|
printM_ r |
戻る |
1 9 |
|
2 10 |
|
3 11 |
|
4 12 |
|
|
ジャグ配列を(行を先に)ほどいて2次元配列にする |
|
Function unzipR(ByRef
vec As Variant) As Variant |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
|
|
printM unzipR(zipR(m))
' 元に戻る |
|
1 2 3 4 |
|
5 6 7 8 |
戻る |
9 10 11 12 |
|
|
2次元配列の各列ベクトルをzipVs |
|
Function zipC(ByRef
m As Variant, Optional ByRef target As Variant) As Variant |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
|
|
c = zipC(m) |
|
printM c |
|
[0] [1] [2] |
|
printM_ c |
|
|
|
5 6
7 8 |
戻る |
9 10 11 12 |
|
|
|
r = zipC(m, Array(0, 2))
← 対象列を指定 |
|
printM_ r |
|
1 3 |
|
5 7 |
|
9 11 |
|
|
ジャグ配列を(列を先に)ほどいて2次元配列にする |
|
Function unzipC(ByRef
vec As Variant) As Variant |
|
|
|
m = makeM(3, 4, iota(1, 12)) |
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
|
|
printM unzipC(zipC(m))
' 元に戻る |
|
1 2 3 4 |
|
5 6 7 8 |
戻る |
9 10 11 12 |
|
|
zipVsされたジャグ配列をほどいてzipVs前の1次元配列または2次元配列にする |
|
Public Function unzip(ByRef vec As Variant, Optional ByVal dimen As Long = 1) As
Variant |
|
|
|
printM m |
|
1 2 3 4 |
|
5 6 7 8 |
|
9 10 11 12 |
|
c = zipR(m) |
|
printM_ c |
|
|
|
|
|
3 7
11 |
|
4 8
12 |
|
printM_ unzip(c) |
戻る |
|
|
5 6
7 8 |
|
9 10 11 12 |
|
|
|
printM unzip(c, 2) |
|
1 5 9
← ジャグ配列ではない。2次元配列 |
|
2 6
10 |
|
3 7
11 |
|
4 8
12 |
|
|
|
|
Array(a)作成 |
|
Function makeSole(ByRef a As Variant, Optional ByRef dummy As Variant) As
Variant |
|
|
|
Public Function p_makeSole( |
|
|
Array(a, b)作成 |
|
Function makePair(ByRef a As Variant, ByRef b As Variant) As Variant |
|
|
|
Public Function p_makePair( |
|
|
配列の先頭に要素を追加 |
|
Function cons(ByRef
a As Variant, ByRef vec As Variant) As Variant |
|
|
戻る |
Public Function p_cons( |
|
|
1次元配列の末尾に要素を追加(LBoundは0に変更する) |
|
Sub push_back(ByRef
vec As Variant, ByRef a As Variant) |
|
|
|
m = iota(1, 10) |
|
printM m |
|
1 2
3 4 5
6 7 8
9 10 |
|
push_back m,
99 |
|
printM m |
|
1 2
3 4 5
6 7 8
9 10 99 |
|
|
push_backしてmoveして返す |
|
Function push_back_move(ByRef vec As Variant, ByRef a As Variant) As Variant |
|
|
|
Public Function p_push_back_move( |
|
|
配列を平坦な1次元配列化する |
|
Function flatten(ByRef
vec As Variant, Optional ByRef dummy As Variant) As Variant |
|
|
戻る |
Public Function p_flatten( |
|
|
|
m = Array(1, 2, 3, iota(1, 10), 4, 5, 6) |
|
printM m |
|
1 2
3 [3] 4
5 6 |
|
printM flatten(m) |
|
1 2
3 1 2
3 4 5
6 7 8
9 10 4
5 6 |
|
|
ベクトルの直積に関数を適用した行列を作る |
|
Public Function product_set(ByRef pCallback As Variant, ByRef a As Variant, ByRef b As
Variant) As Variant |
|
|
|
printM product_set(p_mult, iota(1, 9), iota(1, 9)) |
|
1 2 3 4 5 6 7 8 9 |
|
2 4 6 8 10 12 14 16 18 |
|
3 6 9 12 15 18 21 24 27 |
|
4 8 12 16 20 24 28 32 36 |
|
5 10 15 20 25 30 35 40 45 |
|
6 12 18 24 30 36 42 48 54 |
|
7 14 21 28 35 42 49 56 63 |
|
8 16 24 32 40 48 56 64 72 |
|
9 18 27 36 45 54 63 72 81 |
|
|