How do I find .index of a multidimensional array

后端 未结 7 1655
-上瘾入骨i
-上瘾入骨i 2021-02-08 19:34

Tried web resources and didnt have any luck and my visual quick start guide.

If I have my 2d/multidimensional array:

 array = [[\'x\', \'x\',\' x\',\'x\'         


        
7条回答
  •  情书的邮戳
    2021-02-08 20:10

    You could find first in which is the absolute position by flattening the array:

    pos = array.flatten.index('S')
    

    Then get the number of columns per row:

    ncols = array.first.size
    

    then

    row = pos / ncols
    
    col = pos % ncols
    

提交回复
热议问题