0
我正在尝试通过遍历2D array
来查找average
。遍历二维数组并获得其相邻单元格的平均值
middle
中的值必须计算为4边的平均值(Top,Bottom,Left,Right and recalculated)
。我必须找到当前指数的四面值,并用该数字替换当前的指数。任何想法,将不胜感激。
final public class Matrix {
private final int M; // number of rows
private final int N; // number of columns
private final double[][] data; // M-by-N array
// create M-by-N matrix of 0's
public Matrix(int M, int N) {
this.M = M;
this.N = N;
data = new double[M][N];
}
// create matrix based on 2d array
public Matrix(double[][] data) {
M = data.length;
N = data[0].length;
this.data = new double[M][N];
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
this.data[i][j] = data[i][j];
}
// copy constructor
private Matrix(Matrix A) { this(A.data); }
// print matrix to standard output
public void show() {
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++)
System.out.printf("%.1f ", data[i][j]);
System.out.println();
}
}
// test client
public static void main(String[] args) {
double[][] d = { { 22.5,30,30,30,30,30,30,30,30,51 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 15,0,0,0,0,0,0,0,0,72 },
{ 45,75,75,75,75,75,75,75,75,73.5 }
};
Matrix D = new Matrix(d);
D.show();
System.out.println();
}
}
ConvolveOp
有一个很难理解你的问题。即在索引[0] [0] b/c处发生了什么,不存在四条边?另外,重新计算在哪里开始和停止?请澄清。 –在[0] [0]我只是硬编码其两个相邻边的平均值,它们是(30 + 15/2) – Javazilla
当网格总误差小于5.0时,重新计算必须停止 – Javazilla