Home > front end >  How to reshape the flutter (dart) list
How to reshape the flutter (dart) list

Time:05-14

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]

CodePudding user response:

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]
  • Related