在 la4j 中将一个矩阵插入另一个矩阵

Inserting one matrix into other in la4j

我正在使用 la4j 库。我有这个代码:

Matrix sparse = new CCSMatrix(3, 3);
Matrix newSparse = new CCSMatrix(4, 4);
sparse.setAll(5);
newSparse.insert(sparse);
System.out.println(sparse.toCSV());
System.out.println(newSparse.toCSV());

现在的输出是:

5,000, 5,000, 5,000
5,000, 5,000, 5,000
5,000, 5,000, 5,000

0,000, 0,000, 0,000, 0,000
0,000, 0,000, 0,000, 0,000
0,000, 0,000, 0,000, 0,000
0,000, 0,000, 0,000, 0,000

为什么 newSparse 矩阵不包含 sparse 矩阵?

la4j中的所有操作默认都是错位的。所以你必须这样做:

Matrix sparse = new CCSMatrix(3, 3);
Matrix newSparse = new CCSMatrix(4, 4);
sparse.setAll(5);
newSparse = newSparse.insert(sparse);