How can we get the coordinates of a n dimensions matrix from its shape and its flatten index?
I mean, if for example I have the following (2,3) matrix of 2 dimensions:
...and I want to find the value of the index in red from the coordinates [0,2], how can I do?Code:[ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ]
Or if I have this (2,2,5) matrix of 3 dimensions:
...and I know the coordinates that I want have a flatten index value of 9, how can I find the relative coordinates are: [1,0,2]?Code:[ [ [ nil, nil ], [ nil, nil ] ], [ [ nil, nil ], [ nil, nil ] ], [ [ nil, 9 ], [ nil, nil ] ], [ [ nil, nil ], [ nil, nil ] ], [ [ nil, nil ], [ nil, nil ] ] ]
If possible, I would like to know a general and simple method, which work on matrix of any shape.
Many thanks for your help.


LinkBack URL
About LinkBacks