Esempio n. 1
0
// OuterProduct returns the outer product for real Vectors
func OuterProduct(vectorA ct.Vector, vectorB ct.Vector) (ct.Matrix, error) {
	if vectorA.Type() != ct.ColVector || vectorB.Typ() != ct.RowVector {
		return nil, errors.New("One or both vector types are not consistent with the vector inner product")
	}

	matrix := ct.MakeMatrix(vectorA.Dim(), vectorB.Dim())

	for i := 0; i < vectorA.Dim(); i++ {
		for j := 0; j < vectorB.Dim(); j++ {
			matrix.Set(i, j, vectorA.Get(i)*vectorB.Get(j))
		}
	}

	return matrix, nil
}