我想將mat.Dense矩陣與mat.VecDense向量相乘,但顯然mat.Dense 也mat.VecDens沒有實現矩陣接口或定義將矩陣與向量相乘的方法。我該怎么做?
1 回答

BIG陽
TA貢獻1859條經驗 獲得超6個贊
解決了。
mat.NewVecDense(...)返回一個*mat.VecDense,它實現了一個方法func MulVec(a mat.Matrix, b mat.Vector)
這是驗證功能的測試
func TestMatrixVectorMul(t *testing.T) {
a := mat.NewDense(3, 3, []float64{
1, 2, 3, 4, 5, 6, 7, 8, 9,
})
b := mat.NewVecDense(3, []float64{
1, 2, 3,
})
actual := make([]float64, 3)
c := mat.NewVecDense(3, actual)
// this was the method, I was looking for.
c.MulVec(a, b)
expected := []float64{14, 32, 50}
assert.Equal(t, expected, actual)
}
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消