From: "Paul A." Date: 2011-05-09T15:37:33+09:00 Subject: Re: Index to coordinates conversion, according the matrix shape Hashmal wrote in post #997453: > This is a perfect case for modulo (%). It gives the remainder of a > division. > > def index_to_coordinates arr_size, index > x = index % arr_size[0] > y = (index - x) / arr_size[0] > return x, y > end > > coordinates [3, 3], 3 # => [0, 1] > Waw, thanks. But... is this okay with matrix of more then 2 dimensions? :) Such as this one: NArray.object(2,3,2): [ [ [ nil, nil ], [ nil, nil ], [ nil, nil ] ], [ [ nil, nil ], [ nil, nil ], [ nil, nil ] ] ] -- Posted via http://www.ruby-forum.com/.