2016-09-16 28 views
0

下面的示例嘗試乘以Double類型的標量數與SparseVector[(Int, Double)]如何將SparseVector與Breeze中的標量相乘?

val a = SparseVector(10)(3 -> 1.0, 6 -> 2.0, 9 -> 3.0) 
val b = 5.0 * a 

代碼編譯失敗,因爲

Error: could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2[Double,breeze.linalg.SparseVector[(Int, Double)],That] val b = 5.0 * a

看來這種類型乘法的隱含的實現是失蹤。

然而,如果我們做同樣的事情在DenseVector[Double],一切都很好:

val a = DenseVector(1.0, 2.0, 3.0) 
val b = 5.0 * a 

我錯過了一個包,我應該爲進口稀疏的情況下?

回答

0

使用:*進行縮放而不是*

a :* 5.05.0 *: a