日期:2014-05-20  浏览次数:20833 次

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); 
    } 
}