[英]Scala type mismatch while using Map
I was trying to create a map that goes from integers to Nd4j arrays (as in INDArrays
) using the nd4s library. 我正在尝试使用nd4s库创建一个从整数到Nd4j数组(如
INDArrays
)的映射。 I'm struggling with this issue: 我正在努力解决这个问题:
import org.nd4j.linalg.factory._
scala> Map(0 -> Nd4j.create(2))
<console>:17: error: type mismatch;
found : org.nd4j.linalg.api.ndarray.INDArray
required: Int
Map(0 -> Nd4j.create(2))
^
If I set the key type as string, it works: 如果我将密钥类型设置为字符串,则可以使用:
scala> Map("0" -> Nd4j.create(2))
res28: scala.collection.immutable.Map[String,org.nd4j.linalg.api.ndarray.INDArray] = Map(0 -> [ 0.00, 0.00])
It works also by inverting key and value type. 它也可以通过反转键和值类型来工作。
I can't understand what is happening. 我不明白发生了什么。
I found the answer by asking help on the Scala channel on gitter. 我通过在Scatter的Scala频道上寻求帮助找到了答案。
The problem is that nd4s does an implicit conversion for the -> operator, leading to this issue. 问题是nd4s对->运算符进行隐式转换,从而导致此问题。
https://github.com/deeplearning4j/nd4s/blob/master/src/main/scala/org/nd4s/Implicits.scala#L143-L176 https://github.com/deeplearning4j/nd4s/blob/master/src/main/scala/org/nd4s/Implicits.scala#L143-L176
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.