This commit is contained in:
Will Charczuk 2017-04-17 12:22:44 -07:00
parent 88499d5576
commit 724d6e3c2a
3 changed files with 84 additions and 3 deletions

17
matrix/vector.go Normal file
View file

@ -0,0 +1,17 @@
package matrix
// Vector is just an array of values.
type Vector []float64
// DotProduct returns the dot product of two vectors.
func (v Vector) DotProduct(v2 Vector) (result float64, err error) {
if len(v) != len(v2) {
err = ErrDimensionMismatch
return
}
for i := 0; i < len(v); i++ {
result = result + (v[i] * v2[i])
}
return
}