さまざまな長さの行列を平坦化するための高速で優れた方法を提案するすべて、
私はこれを行う方法を知っているが、私はそれが最も効率的な方法だとは思わない。これをより効率的にするための考えはありますか?
Matrix1 = [1,2,3,4,5];
Matrix2 = [2,3,5];
Matrix3 = [7,8,9,10];
ColAVals = {};
ColBVals = {};
ColCVals = {};
for(i = 1, i <= N rows(Matrix1), i++,
for(r = 1, r <= N rows(Matrix2), r++,
for(s = 1, s <= N rows(Matrix3), s++,
Insert Into(ColAVals,Matrix1[i]);
Insert Into(ColBVals,Matrix2[r]);
Insert Into(ColCVals,Matrix3[s]);
);
);
);
Show(ColAVals);
Show(ColBVals);
Show(ColCVals);
dt = New Table("Test");
dt << New Column("A",Numeric,Continuous, << set Values(ColAVals))
<< New Column("B",Numeric,Continuous, << set Values(ColBVals))
<< New Column("C",Numeric,Continuous, << set Values(ColCVals));再:さまざまな長さの行列を平坦化するためのより速くより良い方法を提案するこの方法は比較的速いようです。
nmat = 15;
matrices = {};
For( i = 1, i <= nmat, i++,
matrices[i] = J( Random Integer( 5 ), 1, Random Uniform() )
);
start = Tick Seconds();
m1 = As Table( matrices[1] );
m2 = As Table( matrices[2] );
dt = m1 << Join( With( m2 ), Cartesian Join, private );
Close( m1, nosave );
Close( m2, nosave );
For( i = 3, i < N Items( matrices ), i++,
mi = As Table( matrices[i] );
dt = dt << Join( With( mi ), Cartesian Join, private );
Close( mi, nosave );
);
mlast = As Table( matrices[N Items( matrices )] );
dt = dt << Join( With( mlast ), Cartesian Join );
Close( mlast, nosave );
end = Tick Seconds();
total = end - start;
Show( total );
ところで、デカルト結合には注意してください。デカルト結合は本当に速くなります。;-)
再:さまざまな長さの行列を平坦化するためのより速くより良い方法を提案するデカルト座標系をすべての行列に結合したいですか。
繰り返しますが、タイミングテストは行っていませんが、これについてはどうですか。
Matrix1 = [1, 2, 3, 4, 5];
Matrix2 = [2, 3, 5];
Matrix3 = [7, 8, 9, 10];
dts = {};
dts[1] = As Table( matrix1 );
dts[2] = As Table( matrix2 );
dts[3] = As Table( matrix3 );
dt = dts[1] << Join( With( dts[2] ), Cartesian Join );
For( i = 3, i <= N Items( dts ), i++,
dt = dt << Join( With( dts[i] ), Cartesian Join );
);再:さまざまな長さの行列を平坦化するためのより速くより良い方法を提案する @Jeff_Perkinson 、
データテーブルへの変換ではなく、ループが心配です。また、結果として得られるテーブルに、次のようなすべての可能な組み合わせを含めるようにします。

再:さまざまな長さの行列を平坦化するためのより速くより良い方法を提案するタイミングテストは行っていませんが、このようにAs Table()を使用する方が速い場合があります。
matrix1 = [1,2,3,4,5];
matrix2 = [2,3,5];
matrix3 = [7,8,9,10];
maxrows=maximum(nrow(matrix1), nrow(matrix2), nrow(matrix3));
matrix1 = matrix1 |/ j(maxrows-nrow(matrix1), 1, .);
matrix2 = matrix2 |/ j(maxrows-nrow(matrix2), 1, .);
matrix3 = matrix3 |/ j(maxrows-nrow(matrix3), 1, .);
mat=matrix1 || matrix2 || matrix3;
dt=as table(mat);