【发布时间】:2014-04-03 12:01:31
【问题描述】:
在一个函数中,我有两个二维数组(超过 50x50)作为输入,它们都具有相同的 Nr。列但不同的编号。行。 基本上我需要删除包含 0 到 2 范围内数字的公共列
例子:
A: 3 0 0 0 0 1 0
5 0 0 6 0 0 2
2 0 0 7 1 0 0
B: 2 3 0 1 0 0 1
4 9 0 2 0 0 0
在这种情况下,我必须删除第 3 列、第 6 列和第 7 列(到 A 和 B),因为第 3 列只有 0,第 6 列只有 0 和 1,最后一列都是 Nr。从 0 到 2。
我可以使用像 LinearAlgebra.deleteColumns(A , 2 , 5,6); 和 LinearAlgebra.deleteColumns(B, 2, 5,6); 这样的函数但由于我的输入数组很大,我必须对两个数组进行列解析。
有什么想法可以解决这个问题吗?这是使用 3 个 for 循环(java)的原始想法
for(int col=0; col < A[0].length; col++){ // step through each column
int cnt = 0;
for(int row = 0; row < B.length ; row ++){
if(!(B[col][row].equals(0 | 1 | 2))) {
cnt++;
}
}
if(cnt == 0) {
// store number of column -> use later on LinearAlgebra.deleteColumns
}
for(int row = 0; row < A.length ; row++){
if(!(A[col][row].equals(0 | 1 | 2)))
cnt++;
}
if(cnt == 0){
// check aswell all values of B otherwise iterate next column
}
}
【问题讨论】:
标签: java arrays parsing matrix