【发布时间】:2016-02-02 03:14:54
【问题描述】:
我有一个巨大的点数据类型列表和一个大小相等的双列表。大小可能在 1000000 左右。两个列表都来自不同的类。
List<Point> XYPair; E.g. { (10,10),(10,10).......(20,20),(20,20).....}
List<double> ZValue; E.g. { 1.5, 1.6, .............7.8,8.7......}
我需要将唯一的 XY 对绘制为 X 和 Y 坐标。但是要为单个XY 应用markercolor,我需要为单个XY 查找所有相应的ZValue 并应用统计信息。 XYPair 和 ZValue 的索引匹配。是否可以使用 LINQ 来查找来有效地实现这一点,而不是像下面这样得到内存不足的预期错误?
目前我正在这样做:
GroupedPlotValues = XYLocation
.Select(bv => bv.ElementAt(0))
.Select((p, i) => new { Item1 = p, Item2 = i })
.GroupBy(tp => tp.Item1, tp => tp.Item2)
.ToDictionary(gr => gr.Key, gr => gr.ToList());
foreach (var item in GroupedPlotValues)
{
var matched = item.Value.Intersect(MatchingIndexes).ToList();
if (matched.Count != 0)
{
chart1.Series[0].Points.AddXY(item.Key.X, item.Key.Y);
var singleZGroup = item.Value.Select(y => ZColumn[y]).ToList();
ApplyStatistics(singleZGroup);
}
}
【问题讨论】:
-
XYPair 是否与 ZValue 1:1 匹配?换言之,ZValue[0] 是否应用于 XYPair[0],ZValue[1] 是否应用于 XYPair[1],等等?另外,我不明白您的 GroupedPlotValues = ... 代码在做什么,因为代码中引用的类型似乎与问题开头的类型(XYPair 和 ZValue)无关
-
是的!!! XYPair 与 ZValue 1:1 匹配。 GroupedPlotValues 正在创建一个字典,其中包含一个 xy 键和多个对应的 ZValues 索引。后面的代码,即 singleZGroup 获取匹配索引的对应值。
-
为避免内存不足异常,您必须避免将所有数据加载到内存中。