Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 F# 中获取 2D 数组的列或行(理想情况下作为 1D 数组,但 Seq 也会很好)。显然我可以自己写,但你会认为它必须已经提供......
例如,我在内置等效项之后:
let row i array = seq { for j in 0 .. (Array2D.length2 array)-1 do yield array.[i,j]}
我不认为有一个内置的功能。
您可以使用Seq.cast对数组进行切片并展平切片:
let row i (arr: 'T[,]) = arr.[i..i, *] |> Seq.cast<'T>