Matrix Addition and Multiplication using owl
Task
Mathematics / Vector & Matrix Operations / Matrix Addition and Multiplication
Opam Packages Used
- owl Tested with version: 1.1 — Used libraries: owl
Code
Create two 2x2 matrices from 1D arrays
let m1 =
Owl.Mat.of_array [|1.;2.;3.;4.|] 2 2
let m2 =
Owl.Mat.of_array [|5.;6.;7.;8.|] 2 2
let add = Owl.Mat.( m1 + m2 );;
let mul = Owl.Mat.( m1 *@ m2 );;
let () =
Owl.Mat.iteri_2d
(fun i j a ->
Printf.printf "(%i,%i) %.1f\n" i j a)
add;;
let () =
Owl.Mat.iteri_2d
(fun i j a ->
Printf.printf "(%i,%i) %.1f\n" i j a)
mul;;