首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq select的有关问题

2012-04-06 
linq select的问题public class Example{public double[] vectorpublic double labelpublic Example(dou

linq select的问题
public class Example
  {
  public double[] vector;
  public double label;

  public Example(double[] v, double l) { vector = v; label = l; }
  }
这个是基本对象
  //PINQueryable可以继承iQueryable 
  public static double[] PerceptronStep(PINQueryable<Example> input, double[] normal, double epsilon)
  {
  // select the examples that are currently mis-labeled by the normal vector
  var errors = input.Where(x => x.label * x.vector.Select((v, i) => v * normal[i]).Sum() < 0.0);


请问最后一句中的 v代指什么?
整个最后一句是什么意思?

万分感谢

[解决办法]
x.vector.Select((v, i) => v * normal[i],v应该是vector的元素,i也该是相应v所在的索引
做一个判断,在input中找出对Vector中的每一个元素与Normal数组对应的值相乘,然后求和,在与 x.label相乘的结果小于0的数据
[解决办法]
v 代表 x.vector集合的其中一个元素
i 代表v在集合中的索引
可参考:

C# code
public void Linq12() {     int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };       var numsInPlace = numbers.Select((num, index) => new { Num = num, InPlace = (num == index) });       Console.WriteLine("Number: In-place?");     foreach (var n in numsInPlace)     {         Console.WriteLine("{0}: {1}", n.Num, n.InPlace);     } } 

热点排行