You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MXNet Scala中one_hot函数参数报错,请求排查原因

解决MXNet Scala one_hot函数"找不到indices参数"的问题

问题原因

我来帮你排查这个问题!你遇到的错误核心原因是:MXNet Scala的one_hot函数并不支持用Map传递所有参数。你错误地把必填的indices放进了参数Map里,但实际上Scala版本的API要求indices作为第一个位置参数直接传入,其余参数才是可选的命名参数。

从错误提示里的Possible Arguments列表也能看出,官方列出的可选参数里没有indices——因为它是必须的位置参数,不属于通过Map传递的键值对范畴。

修正后的代码

把你的代码调整成如下形式,就能正常运行了:

object LoadTest1 {
  def main(args: Array[String]): Unit = {
    var b = NDArray.array(Array(1, 2, 3), shape = Shape(1, 3))
    // 单独创建indices数组作为位置参数
    val indices = NDArray.array(Array(1f, 2f, 3f), shape = Shape(1, 3))
    // 正确调用one_hot:indices放第一个位置,其余参数用命名方式传递
    val a = NDArray.one_hot(indices, depth = 4, on_value = 1.0, off_value = 0.0, dtype = "float16")
    println(a)
    println("-----------------------")
  }
}

额外说明

  • MXNet Scala的one_hot函数签名大致为:def one_hot(indices: NDArray, depth: Int, on_value: Double = 1.0, off_value: Double = 0.0, dtype: String = "float32"): NDArray
  • 你原代码末尾的(1)(1)是多余的,修正后的调用不需要这部分
  • 注意on_value和off_value的类型是Double,写成1.0会更规范(不过Scala支持隐式转换,写1也能运行)

内容的提问来源于stack exchange,提问作者Guox Duan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:34:52