首页 > 解决方案 > 在 OjAlgo 的 Primitive64Store 中的特定列和行处插入 Access2D 元素

问题描述

是否可以在 OjAlgo 的 Primitive64Store 中插入 Access2D 元素?

    Access2D<Double> data = Access2D.wrap(mu.toRawCopy2D());
    Primitive64Store B = Primitive64Store.FACTORY.make(rows * m, columns * n);

我想在特定的起始行和起始列将数据插入 B 中。

暂时。我已经实现了这样的程序:

public class Repmat {

    static public MatrixStore<Double> repmat(MatrixStore<Double> mu, int m, int n) {
        long rows = mu.countRows();
        long columns = mu.countColumns();
        double[][] data = mu.toRawCopy2D();
        Primitive64Store B = Primitive64Store.FACTORY.make(rows * m, columns * n);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                for(int k = 0; k < rows; k++) {
                    B.fillRow(i * rows + k, j * columns, Access1D.wrap(data[k])); // Get row from data and place it into B
                }
            }
        }
        return B.get();
    }
} 

但这一定是更好的方法吗?

标签: javaojalgo

解决方案


也许是这样的:

static public MatrixStore<Double> repmat(MatrixStore<Double> mu, int m, int n) {

    LogicalBuilder<Double> builder = mu.logical();

    for (int i = 1; i < m; i++) {
        builder.below(mu);
    }

    MatrixStore<Double> firstCol = builder.get();

    for (int j = 1; j < n; j++) {
        builder.right(firstCol);
    }

    return builder.get();
}

推荐阅读