In a multidimensional sequence created with tabulate, is the innermost seq the 1. dimension?

让人想犯罪 __ 提交于 2019-12-11 13:57:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!