【问题标题】:What is the standard way to find the elements count in a 2D jagged array?在二维锯齿状数组中查找元素计数的标准方法是什么?
【发布时间】:2016-11-04 01:19:56
【问题描述】:
    public static double PrazenWindowDensity(double [][] Xn, double x, double sigma2)
    {
        double gauss = 0;

        foreach(double [] arr in Xn)
        {
            foreach (double item in arr)
            {
                double xx = GausianFunction(item, x, sigma2);
                gauss += xx;
            }
        }

        return gauss / Xn.Length; //this is surely incorrect. Isn't it?
    }

我可以在这里写什么?

return gauss / Xn.Length;

【问题讨论】:

标签: c# arrays multidimensional-array jagged-arrays


【解决方案1】:

我认为最快、最简单的方法是

public static double PrazenWindowDensity(double[][] Xn, double x, double sigma2)
{
    double gauss=0;
    int count=0;
    for (int i=0; i<Xn.Length; i++)
    {
        gauss+=Xn[i].Sum((item) => GausianFunction(item, x, sigma2));
        count+=Xn[i].Length;
    }
    return gauss/count;
}

【讨论】:

    【解决方案2】:

    这似乎是一个令人满意的答案,所以我将继续发布它。

    return gauss / Xn.Sum(x => x.Length);
    

    【讨论】:

      猜你喜欢
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 2015-10-18
      • 2014-04-21
      • 2012-01-20
      • 2013-07-07
      • 1970-01-01
      相关资源
      最近更新 更多