以下示例尝试将Double
类型的标量数乘以SparseVector[(Int, Double)]
:
val a = SparseVector(10)(3 -> 1.0, 6 -> 2.0, 9 -> 3.0)
val b = 5.0 * a
代码无法编译,因为
错误:无法找到参数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 :(得分:1)
使用:*
进行缩放,而不是*
。
a :* 5.0
或5.0 *: a
。