F#创建2D数组 [英] F# Create 2D Array

查看:84
本文介绍了F#创建2D数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在F#中创建大小为1000x1000的2D数组,并使用2DArray类将数组中任意位置的值初始化为其索引的相同值.

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.

即位置[1,1]的值为(1,1).

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

我看过Array2D.create的语法,但不确定如何正确使用它...

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

任何帮助将不胜感激...

Any help would be appreciated...

推荐答案

使用 Array2D .init传递一个函数来指定每个函数的初始值.

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

这篇关于F#创建2D数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆