'How to reshape the flutter (dart) list
Iam working with tflite library which requires an array with shape of [1, 150, 3] and i have 3 arrays of [150], when i try to make a list of the 3 list it shapes become [3, 150] and when using .reshape() it ruins the whole order i just need to reverse the dimensions of the list.
code snippets:
[rs, gs, bs].reshape([150, 3]
simple explanation What happens:
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]
What i need:
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]
Solution 1:[1]
Use the transpose method from: 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]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tray Denney |