Linear array to matrix

Giovanni Di Maria calimero22 at yahoo.it
Sat Apr 4 11:17:03 UTC 2020


On Saturday, 4 April 2020 at 10:52:30 UTC, MoonlightSentinel 
wrote:
> 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



Thank you very much.
Giovanni



More information about the Digitalmars-d-learn mailing list