久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='fy0Pv'></tfoot>
    1. <legend id='fy0Pv'><style id='fy0Pv'><dir id='fy0Pv'><q id='fy0Pv'></q></dir></style></legend>

    2. <i id='fy0Pv'><tr id='fy0Pv'><dt id='fy0Pv'><q id='fy0Pv'><span id='fy0Pv'><b id='fy0Pv'><form id='fy0Pv'><ins id='fy0Pv'></ins><ul id='fy0Pv'></ul><sub id='fy0Pv'></sub></form><legend id='fy0Pv'></legend><bdo id='fy0Pv'><pre id='fy0Pv'><center id='fy0Pv'></center></pre></bdo></b><th id='fy0Pv'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fy0Pv'><tfoot id='fy0Pv'></tfoot><dl id='fy0Pv'><fieldset id='fy0Pv'></fieldset></dl></div>
      • <bdo id='fy0Pv'></bdo><ul id='fy0Pv'></ul>

      <small id='fy0Pv'></small><noframes id='fy0Pv'>

      對二維數(shù)組的列求和

      Sum columns of a 2D array(對二維數(shù)組的列求和)
      <i id='yq9F3'><tr id='yq9F3'><dt id='yq9F3'><q id='yq9F3'><span id='yq9F3'><b id='yq9F3'><form id='yq9F3'><ins id='yq9F3'></ins><ul id='yq9F3'></ul><sub id='yq9F3'></sub></form><legend id='yq9F3'></legend><bdo id='yq9F3'><pre id='yq9F3'><center id='yq9F3'></center></pre></bdo></b><th id='yq9F3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yq9F3'><tfoot id='yq9F3'></tfoot><dl id='yq9F3'><fieldset id='yq9F3'></fieldset></dl></div>
        <tbody id='yq9F3'></tbody>
      <legend id='yq9F3'><style id='yq9F3'><dir id='yq9F3'><q id='yq9F3'></q></dir></style></legend>

          • <bdo id='yq9F3'></bdo><ul id='yq9F3'></ul>

            <tfoot id='yq9F3'></tfoot>
              1. <small id='yq9F3'></small><noframes id='yq9F3'>

              2. 本文介紹了對二維數(shù)組的列求和的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我有一個 IEnumerable<IEnumerable<double>> 它基本上可以被認為是一個二維數(shù)組,我想做的是得到一個一維數(shù)組(或列表或其他)這是我原始收藏的所有列的總數(shù).換句話說,如果我有:

                I have an IEnumerable<IEnumerable<double>> which can basically be thought of as a 2D array of doubles and what I want to do is get a 1D array (or list or whatever) that is the total for all the columns of my original collection. In other words, if I had:

                1   2   3   4
                2   3   1   6
                3   4   5   6
                -------------
                6   9   9   16
                

                我想要最后一行(顯然,這不是原始集合的一部分).

                I'd want the last line (which is not part of the original collection, obviously).

                有沒有一種簡單的方法可以使用 LINQ 來完成此操作,這樣我就不必遍歷整個事情了?我知道我可以使用 .Sum 合計一行或一列,但我想合計每一行.

                Is there a simple way to do this with LINQ so that I don't have to loop over the whole thing? I know I can use .Sum to total one row or one column, but I want to total each row.

                我看到了一些建議使用 group 的其他問題(主要是處理數(shù)據(jù)庫查詢),但這似乎對我不起作用.我試過這個:

                I've seen some other questions (mostly dealing with database queries) that suggest using group but that didn't seem to work for me. I tried this:

                            var totals = from p in toTotal
                                         group p by 1 into g
                                         select g.Sum(t => t.First()); 
                

                但這只是全部.

                有沒有聰明的方法來做到這一點?

                Is there a clever way to do this?

                例如,如果 toTotal 被定義為:

                for example, if toTotal was defined as:

                    List<List<double>> toTotal = new List<List<double>>() {
                        new List<double> {1,   2,   3,   4},
                        new List<double> {2,   3 ,  1,   6},
                        new List<double> {3 ,  4,   5 ,  6}
                    };
                

                推薦答案

                好的.我想我已經(jīng)成功了:

                Ok. I think I've hit on it:

                var totals = toTotal.Aggregate((prev, next) => prev.Zip(next, (a, b) => a + b));
                

                訣竅是我一直在尋找 Fold(或 Reduce)函數(shù),但在 LINQ 中它被稱為 Aggregate.

                The trick was that I was looking for a Fold (or Reduce) function, but in LINQ it's called Aggregate.

                這里有一個 fiddle 顯示了這個和@Habib 的總行代碼(用于比較).與我在這里(以及我在實際代碼中使用的)的唯一變化是我需要 .ToList .Zip 的結(jié)果,因為對于這個測試用例我有一個 List<List<double>> 如果您沒有明確轉(zhuǎn)換為列表,這似乎會讓編譯器感到不安.在我的實際代碼中, toTotal 是一個 IEnumerable 并且不需要轉(zhuǎn)換.

                Here's a fiddle showing this and @Habib's code for totaling rows (for comparison). The only change from what I have here (and what I was using in my actual code) is that I needed to .ToList the result of .Zip because for this test case I have a List<List<double>> and that seems to upset the compiler if you don't explicitly convert to a list. In my actual code toTotal is an IEnumerable<IEnumerable<double>> and doesn't need converting.

                這篇關于對二維數(shù)組的列求和的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關文檔推薦

                What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                onClick event for Image in Unity(Unity中圖像的onClick事件)
                Running Total C#(運行總 C#)
                Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)

                  • <small id='83PkY'></small><noframes id='83PkY'>

                    <i id='83PkY'><tr id='83PkY'><dt id='83PkY'><q id='83PkY'><span id='83PkY'><b id='83PkY'><form id='83PkY'><ins id='83PkY'></ins><ul id='83PkY'></ul><sub id='83PkY'></sub></form><legend id='83PkY'></legend><bdo id='83PkY'><pre id='83PkY'><center id='83PkY'></center></pre></bdo></b><th id='83PkY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='83PkY'><tfoot id='83PkY'></tfoot><dl id='83PkY'><fieldset id='83PkY'></fieldset></dl></div>
                    <legend id='83PkY'><style id='83PkY'><dir id='83PkY'><q id='83PkY'></q></dir></style></legend>
                      <tbody id='83PkY'></tbody>

                        <tfoot id='83PkY'></tfoot>
                          <bdo id='83PkY'></bdo><ul id='83PkY'></ul>

                          主站蜘蛛池模板: 色欧美综合 | 九九精品在线 | 国产欧美在线观看 | 亚洲精品视频观看 | 久久久久久成人 | 日韩av电影在线观看 | 一级黄色毛片免费 | 国产精品久久久久久一级毛片 | 一a一片一级一片啪啪 | 免费看爱爱视频 | 欧洲免费视频 | 91精品久久| 一级片网站视频 | 精品国产一区二区三区久久久蜜月 | 91久久精品一区二区二区 | 国产精品一二三区 | 中文字幕亚洲区一区二 | 成人h视频在线 | 精品欧美一区二区三区久久久 | 又爽又黄axxx片免费观看 | 老外黄色一级片 | 国产欧美在线一区二区 | 99久久久久国产精品免费 | 欧美精品日韩精品国产精品 | 午夜精品影院 | 在线一区视频 | 精品久久久久久亚洲综合网 | 黄色毛片免费 | 九九热在线观看视频 | 亚洲精品中文字幕在线观看 | 99精品一级欧美片免费播放 | 91一区二区三区 | cao在线 | 国产精品久久久久av | 亚洲一二三区不卡 | 中文字幕一区二区三区乱码在线 | 99re视频 | 亚洲国产精品99久久久久久久久 | 91久久久久久久久久久 | 91亚洲国产成人久久精品网站 | 久久精品亚洲精品国产欧美 |