1

使用 Math.Net Numerics,我如何索引矩阵的各个部分?

例如,我有一个整数集合,我想获得一个子矩阵,其中相应地选择了行和列。

A[2:3,2:3]应该给我 A 的 2 x 2 子矩阵,其中行索引和列索引是 2 或 3

4

2 回答 2

1

只需使用类似的东西

var m = Matrix<double>.Build.Dense(6,4,(i,j) => 10*i + j);
m.Column(2); // [2,12,22,32,42,52]

要访问所需的列,请使用Vector<double> Column(int columnIndex)扩展方法。

于 2015-06-03T09:48:52.327 回答
0

我怀疑您正在寻找类似这种扩展方法的东西。

public static Matrix<double> Sub(this Matrix<double> m, int[] rows, int[] columns)
{
    var output = Matrix<double>.Build.Dense(rows.Length, columns.Length);
    for (int i = 0; i < rows.Length; i++)
    {
        for (int j = 0; j < columns.Length; j++)
        {
            output[i,j] = m[rows[i],columns[j]];
        }
    }

    return output;
}

我省略了异常处理以确保行和列不为空。

于 2017-07-20T15:17:41.673 回答