F# Create 2D Array

匆匆过客 提交于 2019-12-08 15:29:08

问题


Hi I am wanting to create in F# a 2D array of size 1000x1000, with the value in the array at any position to be initialized as the same vaue of its index using the 2DArray class.

i.e. position [1,1] would have value (1,1).

I have looked at the syntaxt of Array2D.create, but am not sure how to use it properly...

Any help would be appreciated...


回答1:


Use Array2D.init to pass a function to specify the initial value of each.

let a = Array2D.init 3 3 (fun x y -> (x,y))
printfn "%A" a


来源:https://stackoverflow.com/questions/3335901/f-create-2d-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!