如何计算三维矩阵的均值,它类似于在matlab中使用平均(数组,3),其中“数组”是三维的。三维阵列沿三维方向的平均值。java等效项
发布于 2015-01-19 14:45:56
对于第三维空间中的每一个元素,你都会得到一个二维矩阵。例如,
int my3darray[][][] = new int[10][20][30];
new2darray = my3darray[i];对于这个2D矩阵,你可以计算平均值。例如,
二维数组的大小可以计算如下:
array.length * array[0].length;那么或多或少这就是你所需要的:
int rows = 2; // you get the size from array.length
int cols = 3; // you get the size from array[0].length
int i, j;
for (i=0;i<rows;i++); {
for (i=0;j<cols;j++); {
sum += res[i][j];
}
}
System.out.println(sum/(rows*cols))如果您使用的是Apache公共数学,则有一个getMean和一个mean函数,您可以这样使用它:
// assume values is a double[] array
double mean = StatUtils.mean(values);https://stackoverflow.com/questions/28026097
复制相似问题