我正在尝试从一个三维数组中删除项目。
我知道最好的方法之一是将数组转换为列表,然后在迭代原始数组时从列表中删除这些项目,然后将列表转换回数组并返回它。
我尝试过这样做,但在返回数组时出现了类型不匹配的错误。我怀疑在从数组转换为列表时没有对维度进行处理。
有什么建议吗?
import java.util.List;
import java.util.Arrays;
public class RepatitionRemoval {
public float[][][] process(float[][][] data) {
//this method with step through all of the the strokes and remove
//points which occupy the same position. This should help with time
//warping regconition
//Change the array to a list
List points = Arrays.asList(data);
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
for (int k = 0; k < data[i][j].length-1; k++) {
//if the current coordinate is the same as the one next
//then remove it
if (data[i][j][k] == data[i][j][k+1]) {
points.remove(data[i][j][k]);
}
}
}
}
float[][][] returnData = points.toArray();
return returnData;
}
}
toArray()
返回一个Object[]
,所以你不能将其赋值给float[][][]
。 - talnicolas