問題
マトリックスにデータがあり、データ テーブルが必要な場合、またはその逆の場合
Data table or matrix?Data table or matrix?データテーブルまたはマトリックス?
解決
行列から新しいデータ テーブルを作成する関数 AsTable() と、テーブル内の数値列から行列を作成するデータ テーブル メソッド GetAsMatrix() があります。
データテーブルに直接インデックスを付ける方法もあります。データテーブルの添字付け。
// make a matrix of 5 rows, 3 cols, random values
mat = J( 5, 3, Random Normal() );
// make a data table from a matrix
dt = As Table( mat );
// make a matrix from a data table
mat2 = dt << GetAsMatrix;
// comparing two matrices returns a matrix of answers
// and the All function returns true if all of the
// matrix values are true
Show( All( mat == mat2 ) );
// use data table subscripting to get a matrix of all
// rows and all columns from the table; the zero subscript
// is used with matrix and data table to mean "all
// rows or all columns"
mat3 = dt[0, 0];
Show( All( mat == mat3 ) );
ありがとう!
データテーブルの添字付けデータテーブルを行列としてインデックス付けする方法について説明します。 JSLマトリックスとは何ですか?に、行列の添え字の使用方法を示します。 したがって、データ テーブル (または行列) を使用すると、テーブルからデータをコピーして行列を作成するのではなく、次のようにどちらかから行を取得できます。
// if dt is a table...
rowVector = dt[ rowNumber, 0 ]; // all columns
rowVector = dt[ rowNumber, { age, height, weight } ]; // selected columns
// if m is a matrix
rowVector = m[ row, 0 ];
rowVector = m[ row, 5::9 ]; // selected items from row
// and both dimensions at once
patch = m[ 3::5, 7::11 ];添字ゼロは「この次元のすべて」を意味します。 マトリックスのインデックス付けは 1 から始まります。
ありがとう、とても便利です。データテーブルから行ベクトルを取得する便利な方法はありますか?
ありがとう!