Linear array to matrix
    MoonlightSentinel 
    moonlightsentinel at disroot.org
       
    Sat Apr  4 10:52:30 UTC 2020
    
    
  
On Saturday, 4 April 2020 at 09:25:14 UTC, Giovanni Di Maria 
wrote:
> Is there a Built-in function (no code, only a built-in function)
> that transform a linear array to a Matrix?
You can combine slide [1] and array [2]:
import std;
void main()
{
     auto input = [10,20,30,40,50,60,70,80,90,100,110,120];
     auto output = input.slide(3, 3).array;
     writeln(input);
     writeln();
     writeln(output);
}
Note that output is a view of input and not a copy.
[1] https://dlang.org/phobos/std_range.html#.slide
[2] https://dlang.org/phobos/std_array.html#.array
    
    
More information about the Digitalmars-d-learn
mailing list