问题
As the title says, when creating a multidimensional sequence in scala with tabulate, is the innermost or outermost sequence the 1. dimension?
For example, in a 2-dimensional Vector v, will v(2) give the second element of the 1. or of the 2. dimension?
回答1:
scala> Array.tabulate(2,3)(_ + 3*_)
res2: Array[Array[Int]] = Array(Array(0, 3, 6), Array(1, 4, 7))
As you can see, the first number refers to the outermost grouping, while the second refers to the second (and so on). In general, all the multidimensional stuff works this way--if you list the dimensions as 3,5,7,2
then a(2)(4)(6)(1)
uses the last valid index in each dimension.
来源:https://stackoverflow.com/questions/3584841/in-a-multidimensional-sequence-created-with-tabulate-is-the-innermost-seq-the-1