简体   繁体   English

计算 ArrayList 的平均值<Float[]> java中返回Float[]的类型

[英]calculate average of ArrayList<Float[]> type that returns Float[] in java

I have an ArrayList of type Float[] , and i am trying to calculate the average of those Float[] in the ArrayList ;我有一个Float[]类型的ArrayList ,我正在尝试计算ArrayList中那些Float[]的平均值; eg:例如:

[1.5,5.5,2.5,3.0,7.5]
[2.5,7.5,4.5,3.5,9.5]
[8.5,5.5,6.5,4.0,1.5]
[5.5,8.5,6.5,2.0,4.5]

and want the final return result of并想要最终的返回结果

[4.5,6.75,5.0,3.125,5.75]][1]
  Float[] newCluster = new Float[cols];
        for (int i=0; i<cols; i++)
        {
            float sum=0;
            for (int j=0;j<cluster1.size();j++)
            {
//                System.out.println(cluster1.get(j)[i]);
                sum += cluster1.get(j)[i];
            }
            newCluster[i] = sum/cluster1.size();
        }
        System.out.println(Arrays.toString(newCluster));
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM