2
我有一個矩陣:Array2D和功能自行車流水線
let DivideAndSubstract value index (matrix: float[,]) =
//something that returns a matrix
,所以我需要這個功能n次應用到我的矩陣這樣的:
matrix
|> DivideAndSubstract matrix.[0,0] 0
|> DivideAndSubstract matrix.[1,1] 1
|> DivideAndSubstract matrix.[2,2] 2
....
|> DivideAndSubstract matrix.[n,n] n
其中n = Array2D.length1矩陣 - 1
我該如何實現這種流水線?
循環應該看起來像'M < - DivideAndSubtract M. [k,k] k M' – 2011-02-26 12:25:52
正確。洗了澡,意識到fold應該是'|> List.fold(fun M k - > DivideAndSubtract M. [k,k] k M)matrix'現在它可以工作,謝謝 – 2011-02-26 12:44:41
你也可以替換'[0..n ] |> List.fold' by {0..n} |> Seq.fold',所以沒有創建列表。 – Stringer 2011-02-26 12:44:58