RosettaCodeData/Task/Matrix-multiplication/Go/matrix-multiplication-2.go

29 lines
548 B
Go
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
package main
2015-11-18 06:14:39 +00:00
import (
"fmt"
2013-04-10 21:29:02 -07:00
2015-11-18 06:14:39 +00:00
mat "github.com/skelterjohn/go.matrix"
)
2013-04-10 21:29:02 -07:00
func main() {
2015-11-18 06:14:39 +00:00
a := mat.MakeDenseMatrixStacked([][]float64{
{1, 2, 3, 4},
{5, 6, 7, 8},
2013-04-10 21:29:02 -07:00
})
2015-11-18 06:14:39 +00:00
b := mat.MakeDenseMatrixStacked([][]float64{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12},
2013-04-10 21:29:02 -07:00
})
2015-11-18 06:14:39 +00:00
fmt.Printf("Matrix A:\n%v\n", a)
fmt.Printf("Matrix B:\n%v\n", b)
p, err := a.TimesDense(b)
if err != nil {
fmt.Println(err)
2013-04-10 21:29:02 -07:00
return
}
2015-11-18 06:14:39 +00:00
fmt.Printf("Product of A and B:\n%v\n", p)
2013-04-10 21:29:02 -07:00
}