简体   繁体   English

您如何从特定点迭代2D数组?

[英]How do you iterate through a 2D array from a specific point?

样本数据表

The following image was created rather hastily, but the premise of my question is outlined within. 以下图像是草率创建的,但在此概述了我的问题的前提。 What I am looking to do is iterate through to a specific part in my CSV file I have loaded into Eclipse and once there, collect the data in that column and average the numerical values and print to the console. 我想要做的是迭代到我已加载到Eclipse的CSV文件中的特定部分,然后在那儿,收集该列中的数据并取平均值,然后打印到控制台。 At first I had thought about manually entering ([1][1] + [1][2] + [1][3]) / 3 , but this for obvious reasons would be too time consuming. 最初,我曾考虑过手动输入([1][1] + [1][2] + [1][3]) / 3 ,但这显然很耗时。 Could I create a loop which moves over 1 column and down 1 row and then start computing from there? 我可以创建一个循环,该循环在1列上下移动1行,然后从那里开始计算吗?

As the data is given row by row in CSV, it would be best to process it in that way. 由于数据是以CSV格式逐行给出的,因此最好以这种方式进行处理。

Psuedocode: 伪代码:

int columnCount = loadHeaders().length;
float[] totals = new float[columnCount];
int rowCount = 0;
for each row {
  rowCount++;
  for each column //skipping first
     totals[rowIndex] += row[columnIndex].data; //add cell to totals
}
float[] averages = totals / rowCount;

我相信您必须将循环变量的初始值指定为2,除非我误解了这个问题。

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

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