java - 在 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();
}
}
但这一定是更好的方法吗?
解决方案
也许是这样的:
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();
}
推荐阅读
- javascript - 标签文本未在 MUIDataTable ReactJS 中更新
- reactjs - 应用到 antd-component 的 styled-components 传递的 CSS 变量在 webpack 在生产模式下编译后消失
- php - WordPress Caldera 表单在验证时显示错误消息
- xamarin - Xamarin iOS - 使用 PlatformEffect 按下时设置按钮的颜色
- c# - 如何在 VR 中为 Unity 设置渲染纹理
- python - 列表索引超出范围?分数
- java - 在 javafx 中拖放一个节点并接受它
- node.js - 使用 PM2 将秘密环境变量传递给 Node 脚本
- python - 使用 Python 从一些数据创建栅格文件
- python-3.x - 训练预测模型时输入形状错误