[英]Problem with evidence parameters in breeze
I'm trying to build a DenseMatrix of Vectors in breeze.我正在尝试在微风中构建向量的密集矩阵。 However I keep getting the error message:
但是我不断收到错误消息:
could not find implicit value for evidence parameter of type breeze.storage.Zero[breeze.linalg.DenseVector[Double]]
for the line:对于该行:
val som: DenseMatrix[DenseVector[Double]] = DenseMatrix.tabulate(5, 5){ (i, j) => DenseVector.rand(20)}
Even though doing something similar with a Scala Array works fine:即使使用 Scala 阵列做类似的事情也可以正常工作:
val som = Array.tabulate(5, 5)((i, j) => DenseVector.rand(20))
I'm not sure what it is I'm doing wrong or what I'm missing?我不确定我做错了什么或我错过了什么? To be honest I don't understand what the error message is telling me... I don't do enough Scala programming to understand this?
老实说,我不明白错误消息告诉我什么......我没有做足够的 Scala 编程来理解这一点? What even is an Evidence parameter and can I explicitly specify it or do I need an implicit?
什么是证据参数,我可以显式指定它还是需要一个隐式参数?
This is because DenseMatrix.tabulate[V]
firstly fills the matrix with zeroes.这是因为
DenseMatrix.tabulate[V]
首先用零填充矩阵。 So there should be an instance of type class Zero
for V
, ie in our case for DenseVector[Double]
.所以应该有一个类型为 class
Zero
的实例V
,即在我们的例子中DenseVector[Double]
。 You can define it yourself eg您可以自己定义它,例如
implicit def denseVectorZero[V: Zero : ClassTag]: Zero[DenseVector[V]] =
new Zero(DenseVector.zeros(0))
ie if we know Zero
for V
then we know Zero
for DenseVector[V]
.即,如果我们知道
V
的Zero
,那么我们知道DenseVector[V]
的Zero
。
Or even easier甚至更容易
implicit def ev[V: ClassTag]: Zero[DenseVector[V]] = new Zero(DenseVector(Array.empty))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.