簡體   English   中英

如何重塑 flutter (dart) 列表

[英]How to reshape the flutter (dart) list

我正在使用 tflite 庫,它需要一個形狀為 [1, 150, 3] 的數組,我有 3 個 arrays [150],當我嘗試列出 3 個列表時,它的形狀變為 [3, 150] 並且當using.reshape() 它破壞了我只需要反轉列表維度的整個順序。

代碼片段:

[rs, gs, bs].reshape([150, 3]

簡單解釋 發生了什么:

before reshape: [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]

after reshape: [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]

我需要的:

before reshape: [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]

after reshape: [1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14], [5, 10, 15]

使用轉置方法來自: https://pub.dev/packages/matrix2d

List before = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, 13, 14, 15]
  ];

  print(before.transpose); //[1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14], [5, 10, 15]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM