views:

38

answers:

1

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?

+3  A: 
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.

Rex Kerr
In the old days, we'd call it row-major order.
Randall Schulz