开发者

How do I add two numeric arrays in F#

I am totally new to F#. I have searched high and low but I cannot find an example for what I want.

let A = [| 1.0, 2.0, 3.0, 4.0 |];; //maybe delimiter with ;
let B = [| 4.0, 3.5, 2.5, 0.5 |];;

let C = A + B;; //how do I define the addition operator for arrays?
/开发者_如何学Python/ expect C=[| 5.0, 5.5, 5.5, 4.5 |]

I have come close with this posting, but it is not what I want.


let inline (++) a b = Array.map2 (+) a b

let A = [| 1.0; 2.0; 3.0; 4.0 |];;
let B = [| 4.0; 3.5; 2.5; 0.5 |];;
let A1 = [| 1; 2; 3; 1 |];;
let B1 = [| 4; 3; 2; 1 |];;

let C = A ++ B
let C1 = A1 ++ B1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜