Here's a not very elegant solution:

1
2
3
4
5
6
7
8
9
10
let m = matrix [[1.0; 2.0; 3.0];
                [4.0; 5.0; 6.0];
                [7.0; 8.0; 9.0]]


let r = [|10.0; 11.0; 12.0|]


let result = Array.init m.NumRows (fun _ -> r) |> Matrix.ofSeq |> (+) m

Mau

By on 5/28/2010 2:19 AM ()

I don't think it's worse than my solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let m = matrix [[1.0; 2.0; 3.0];
                [4.0; 5.0; 6.0];
               

 [7.0; 8.0; 9.0]];;


let r = [|10.0; 11.0; 12.0|];;

let result = matrix [for i in 0..m.NumRows-1 do
               yield
                    [for j in 0..m.NumCols-1 do
                        yield m.[i,j] + r.[j]]];;

Koen

By on 5/28/2010 8:24 AM ()

Was trying to find a method signature that returned a matrix seems like map and mapi are the only ones. When there starts being lots of functions it would be amazing to be able to search for function using a signature, is this already possible ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<code lang=fsharp>open Microsoft.FSharp.Math

let m = matrix [[1.0; 2.0; 3.0];


[4.0; 5.0; 6.0];


[7.0; 8.0; 9.0]]

//changed it to a vector


let r = vector [|10.0; 11.0; 12.0|];;


let result = matrix [[11.0; 13.0; 15.0];


[14.0; 16.0; 18.0];


[17.0; 19.0; 21.0]];;


//maybe something a little more functional


m |> Matrix.mapi( fun i j elemFromM ->  elemFromM + r.[j])

//using matrix basics


let temp = Matrix.init 3 3 ( fun i j -> 1.0 )


temp*Matrix.initDiagonal(r) + m

//i guess this is also doing a for loop


let temp2 = Matrix.init 3 3 (fun i j -> r.Item(j) + m.Item(i,j) )
By on 5/31/2010 3:04 AM ()

When there starts being lots of functions it would be amazing to be able to search for function using a signature, is this already possible ?

Reminds me of this question: [link:stackoverflow.com]

By on 5/31/2010 6:16 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper