How to create and use a multi-dimensional array in Scala?

前端 未结 3 566
悲哀的现实
悲哀的现实 2020-11-28 05:56

How do I create an array of multiple dimensions?

For example, I want an integer or double matrix, something like double[][] in Java.

I know for

相关标签:
3条回答
  • 2020-11-28 06:25

    It's deprecated. Companion object exports factory methods ofDim:

    val cube = Array.ofDim[Float](8, 8, 8) 
    
    0 讨论(0)
  • 2020-11-28 06:28

    Like so:

    scala> Array.ofDim[Double](2, 2, 2)
    res2: Array[Array[Array[Double]]] = Array(Array(Array(0.0, 0.0), Array(0.0, 0.0)), Array(Array(0.0, 0.0), Array(0.0, 0.0)))
    
    scala> {val (x, y) = (2, 3); Array.tabulate(x, y)( (x, y) => x + y )}
    res3: Array[Array[Int]] = Array(Array(0, 1, 2), Array(1, 2, 3))
    
    0 讨论(0)
  • 2020-11-28 06:37

    How to create and use a multi-dimensional array in Scala?

    var dd : Array[(Int, (Double, Double))] = Array((1,(0.0,0.0)))

    0 讨论(0)
提交回复
热议问题