English 中文(简体)
Kotlin/ Multik 库库: 类命名和如何在数组中索引元素
原标题:Kotlin/Multik library: class naming and how to index elements in array
  • 时间:2024-05-16 01:03:13
  •  标签:
  • kotlin

与通过Multik图书馆在科特林使用多维阵列有关的几个问题。

第一个问题:为什么有必要在此同时导入 mk zeros 来获取 mk.zeros ? 我在想,导入 mk 就足够了。我想这是一个通用的Kotlin问题,不是针对Mulitk的。顺便提一下,我在这个例子中是在Linux上的 kotlin 命令行界面工作,该界面有包含Multik材料的合适的分类路径。

>>> import org.jetbrains.kotlinx.multik.api.mk
>>> mk.zeros <Double> (4, 3)
error: unresolved reference: zeros
mk.zeros <Double> (4, 3)
   ^
>>> import org.jetbrains.kotlinx.multik.api.zeros
>>> mk.zeros <Double> (4, 3)
res3: org.jetbrains.kotlinx.multik.ndarray.data.NDArray<kotlin.Double, org.jetbrains.kotlinx.multik.ndarray.data.D2> = [[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]]

第二个问题, 这个时间是针对 Mulitik 的 。 成功创建了 < code>res3 的元素, 我该如何索引?

>>> res3[0, 0]
error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public operator fun MatchGroupCollection.get(name: String): MatchGroup? defined in kotlin.text
res3[0, 0]
^
error: no get method providing array access
res3[0, 0]
    ^

似乎没有定义方括号操作; 我无法找到用于索引的另一种函数。 我无法解答, 因为多克 Github readme (https://github.com/Kotlin/multik

问题回答
  1. zeros is a "https://kotlinlang.org/docs/extensions.html#clospace-of-extensions" rel=“nofollow norefererr” >extension 函数 on Multik (typealias mk ),因此您需要明确导入

  2. res3[0,0] 不正确的语法。 它应该是 res3[0][0]





相关问题
Exposed runs query on all HikariCP open connections

I m running a Ktor server with a PostgreSQL database and just set up the JetBrains Exposed ORM framework with HikariCP for connection pooling (per the recommendation in the Ktor documentation). My ...

SQLite Kotlin issue - no database

I am trying to create boardgamegeek APIs based app in AndroidStudio, however from unknown reason I m getting my database created with no columns. Here s Logical log: (1) no such table: games in "...

Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

热门标签