从下面double array
中删除多行是否有更好方法?
double[] RetDist;
HashSet<int> rowsToRemove = new HashSet<int> { 249, 250, 251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269};
RetDist = dataDist.Where((source, index) => !rowsToRemove.Contains(index)).ToArray();
主要关注:假设我要删除1000行(极端情况),手动指定效率可能非常低: < / p>
HashSet<int> rowsToRemove = new HashSet<int> { 249, 250,...};
编辑 - 到目前为止使用方式:
将array[]
转换为List<>
List<double> Lretdist = RetDist.ToList();
通过indexes
删除系列method
(我最初想要避免)
List<double> test = RemoveIndexRowFromList(Lretdist, "m");
public static List<double> RemoveIndexRowFromList(List<double> lst, string obsfrequency)
{
int idx, totalrow, endindex, del;
totalrow = lst.Count;
switch (obsfrequency)
{
case "d":
idx = 1;
endindex = totalrow - idx;
while (endindex < totalrow)
{
del = totalrow - 1;
lst.RemoveAt(del);
totalrow = lst.Count;
}
break;
case "m":
idx = 20;
endindex = totalrow - idx;
while (endindex < totalrow)
{
del = totalrow - 1;
lst.RemoveAt(del);
totalrow = lst.Count ;
}
break;
}
return lst;
}
切换回array[]
double[] Re = test.ToArray(); // and keep remaining computations using arrays
Ps :我承认这3个额外步骤可能有点sub-optimal
但是它
我想它比hard-coding
要删除的行数要好一些。