• <i id='3KUAj'><tr id='3KUAj'><dt id='3KUAj'><q id='3KUAj'><span id='3KUAj'><b id='3KUAj'><form id='3KUAj'><ins id='3KUAj'></ins><ul id='3KUAj'></ul><sub id='3KUAj'></sub></form><legend id='3KUAj'></legend><bdo id='3KUAj'><pre id='3KUAj'><center id='3KUAj'></center></pre></bdo></b><th id='3KUAj'></th></span></q></dt></tr></i><div id='3KUAj'><tfoot id='3KUAj'></tfoot><dl id='3KUAj'><fieldset id='3KUAj'></fieldset></dl></div>
      <bdo id='3KUAj'></bdo><ul id='3KUAj'></ul>

      1. <legend id='3KUAj'><style id='3KUAj'><dir id='3KUAj'><q id='3KUAj'></q></dir></style></legend>

        <small id='3KUAj'></small><noframes id='3KUAj'>

      2. <tfoot id='3KUAj'></tfoot>

        Sum 多维数组 C#

        时间:2023-06-05

        <i id='iYTJh'><tr id='iYTJh'><dt id='iYTJh'><q id='iYTJh'><span id='iYTJh'><b id='iYTJh'><form id='iYTJh'><ins id='iYTJh'></ins><ul id='iYTJh'></ul><sub id='iYTJh'></sub></form><legend id='iYTJh'></legend><bdo id='iYTJh'><pre id='iYTJh'><center id='iYTJh'></center></pre></bdo></b><th id='iYTJh'></th></span></q></dt></tr></i><div id='iYTJh'><tfoot id='iYTJh'></tfoot><dl id='iYTJh'><fieldset id='iYTJh'></fieldset></dl></div>
              <tbody id='iYTJh'></tbody>
              <bdo id='iYTJh'></bdo><ul id='iYTJh'></ul>
            • <legend id='iYTJh'><style id='iYTJh'><dir id='iYTJh'><q id='iYTJh'></q></dir></style></legend>
            • <small id='iYTJh'></small><noframes id='iYTJh'>

            • <tfoot id='iYTJh'></tfoot>

                  本文介绍了Sum 多维数组 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如何从多维数组中取出一些值,然后计算平均选择值?

                  How do I sort out some values from multidimensional Array and then calculate the average selected value?

                  所以当我点击某个图像时,它不仅应该在鼠标指针所在的点显示深度数据(来自 Microsoft Kinect),而且还应该计算环境中的值(即多维数组).

                  So when I click some Image, it should show depth data (from Microsoft Kinect) not only in the point where the mouse pointer stands, but also it should calculate the value in the environment (which is multidimensional Array).

                  这是我的代码:

                      protected void imageIR_MouseClick(object sender, System.Windows.Input.MouseEventArgs e)
                      {
                          // Get the x and y coordinates of the mouse pointer.
                          System.Windows.Point mousePoint = e.GetPosition(imageIR);
                          double xpos_IR = mousePoint.X;
                          double ypos_IR = mousePoint.Y;
                          int x = (int)xpos_IR;
                          int y = (int)ypos_IR;
                          lbCoord.Content = "x- & y- Koordinate [pixel]: " + x + " ; " + y;
                          int d = (ushort)pixelData[x + y * this.depthFrame.Width];
                          d = d >> 3;
                          int xpos_Content = (int)((x - 320) * 0.03501 / 2 * d/10);
                          int ypos_Content = (int)((240 - y) * 0.03501 / 2 * d/10);
                          xpos.Content = "x- Koordinate [mm]: " + xpos_Content;
                          ypos.Content = "y- Koordinate [mm]: " + ypos_Content;
                          zpos.Content = "z- Koordinate [mm]: " + (d);
                  
                          // Allocating array size
                          int i = 10;
                          int[] x_array = new int[i];
                          int[] y_array = new int[i];
                          int[,] d_array = new int[i,i];
                  
                          for (int m = 0; m < 10; m++)
                          {
                              for (int n = 0; n < 10; n++)
                              {
                                  x_array[m] = x + m;
                                  y_array[n] = y + n;
                                  d_array[m, n] = (ushort)pixelData[x_array[m] + y_array[n] * this.depthFrame.Width];
                                  d_array[m, n] = d_array[m, n] >> 3;
                              }
                          }
                      }
                  

                  那么,首先:如何对 d_array[m,n] 中的所有值求和?是否可以计算每一行的总和(->一维数组/向量),然后再次计算列的总和(->零维数组/标量)?

                  So, firstly: how do I sum all the values from d_array[m,n] ? Is it possible to calculate the sum of each row (-> one dimensional Array / vector) and then calculate again the sum of the column (-> zero-dimensional Array / scalar)?

                  推荐答案

                  所以,首先:如何对 d_array[m,n] 中的所有值求和

                  So, firstly: how do I sum all the values from d_array[m,n]

                  你可以使用:

                  int sum = d_array.Cast<int>().Sum();
                  

                  这将自动展平多维数组并取所有元素的总和.

                  This will automatically flatten out the multidimensional array and take the sum of all elements.

                  是否可以先计算每一行的总和(->一维数组/向量),然后再计算列的总和(->零维数组/标量)?

                  Is it possible to calculate the sum of each row (-> one dimensional Array / vector) and then calculate again the sum of the column (-> zero-dimensional Array / scalar)?

                  是的,但这需要手动循环.没有一个简单的方法可以解决这个问题,尽管编写方法来处理它很容易,即:

                  Yes, but this would require looping manually. There is no simple one liner for this, though it would be easy to write methods to handle it, ie:

                  IEnumerable<T> GetRow(T[,] array, int row)
                  {
                      for (int i = 0; i <= array.GetUpperBound(1); ++i)
                           yield return array[row, i];
                  }
                  
                  IEnumerable<T> GetColumn(T[,] array, int column)
                  {
                      for (int i = 0; i <= array.GetUpperBound(0); ++i)
                           yield return array[i, column];
                  }
                  

                  你可以这样做:

                  var row1Sum = GetRow(d_array, 1).Sum();
                  

                  这篇关于Sum 多维数组 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:LINQ 和溢出异常? 下一篇:对象上的Linq SUM?

                  相关文章

                  最新文章

                  <tfoot id='xmY74'></tfoot>

                    <legend id='xmY74'><style id='xmY74'><dir id='xmY74'><q id='xmY74'></q></dir></style></legend>
                  1. <i id='xmY74'><tr id='xmY74'><dt id='xmY74'><q id='xmY74'><span id='xmY74'><b id='xmY74'><form id='xmY74'><ins id='xmY74'></ins><ul id='xmY74'></ul><sub id='xmY74'></sub></form><legend id='xmY74'></legend><bdo id='xmY74'><pre id='xmY74'><center id='xmY74'></center></pre></bdo></b><th id='xmY74'></th></span></q></dt></tr></i><div id='xmY74'><tfoot id='xmY74'></tfoot><dl id='xmY74'><fieldset id='xmY74'></fieldset></dl></div>

                  2. <small id='xmY74'></small><noframes id='xmY74'>

                      <bdo id='xmY74'></bdo><ul id='xmY74'></ul>