如何从二维数组 F# 创建直方图

How to create a histogram from a 2d array F#

如何在 F# 中从二维数组创建直方图。

我试过这样的方法:

let histogram =
    Array.iter (fun acc fs -> 
        fs |> List.iter (fun k -> 
            if Map.containsKey k acc
            then Map.add k (acc.[k] + 1) acc
            else Map.add k 1 acc
        )
    ) Map.empty

但我真的想不通如何解决这个问题。 有什么建议可以启动我吗?

如果我没看错的话:

let arr = [| [|1; 2; 4 |] ;[|3; 2; 4 |] ;[|1; 7; 4 |] |]
arr |> Array.concat |> Array.sort |> Seq.groupBy id |> Seq.map(fun el -> fst el,Seq.length (snd el)) 
|> Seq.iter(fun x -> printfn "%d [%d]" (fst x) (snd x)))

输出:

1 [2]
2 [2]
3 [1]
4 [3]
7 [1]

http://ideone.com/P5hmtU