Dr. John A Zoidberg
Dr. John A Zoidberg

Reputation: 1248

Creating a 2D array in F# from a sequence of arrays with similar dimension

Suppose I have a sequence of int arrays, all of the same dimension;

I wish to create a 2D array in which each line n of the 2D array is the nth term in the sequence.

for example, if my sequence is

{[|1 ; 2; 3|] , [|4 ; 5; 6|] , [|7 ; 8; 9|]}

the function should return a 2D array

[|[|1;2;3;],[|4 ; 5; 6|],[|7 ; 8; 9|]|]

Upvotes: 1

Views: 942

Answers (1)

John Palmer
John Palmer

Reputation: 25516

Slightly changing your sequence shows the easiest way (which will work with any combination of inner sequences / arrrays / lists

let t =array2D [[|1 ; 2; 3|] ; [|4 ; 5; 6|] ; [|7 ; 8; 9|]];;

Upvotes: 1

Related Questions