Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5837961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:25:01+00:00 2026-05-22T11:25:01+00:00

How can we get the coordinates of a n dimensions matrix from its shape

  • 0

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:

[ [ 0, 1 ], 
  [ 2, 3 ], 
  [ *4*, 5 ] ]

…and I want to find the value of the index in bold from the coordinates [0,2], how can I do?

Or if I have this (2,2,5) matrix of 3 dimensions:

[ [ [ nil, nil ], 
    [ nil, nil ] ], 
  [ [ nil, nil ], 
    [ nil, nil ] ], 
  [ [ nil, *9*   ], 
    [ nil, nil ] ], 
  [ [ nil, nil ], 
    [ nil, nil ] ], 
  [ [ nil, nil ], 
    [ nil, nil ] ] ]

…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]?

If possible, I would like to know a general and simple method, which work on matrix of any shape.

Many thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:25:02+00:00Added an answer on May 22, 2026 at 11:25 am

    You can use this simple algorithm:

    Let’s say you have the matrix A[a][b][c][d] (where a,b,c,d are the dimensions) and the index X.

    To get the first coordinate of the index X you simply divide X by b*c*d.

    Let it be this next matrix, having the sizes [2][5] and the index X=7

     0 1 2 3 4
     5 6 7 8 9
    

    You first divide X by the last dimension to find the first coordinate. X/5=1 . Then, from there you move forward and give X the value X%=5 . So you’ll have X = 7%5 =2. Now you have to search the coordinates for the remaining dimensions using the same algorithm. If you reach the last dimension , the coordinate will be the remaining X, in this case 2. So the coordinates for X=7 are [1][2] , which is actually the answear.

    Again, for the general case, where you have a,b,c,d dimensions.
    I’ll note with (yd) the y’th dimension.

    X=index
    (1d)=X/b*c*d
    X gets value X % b*c*d
    
    (2d)=X/c*d
    X gets value X % c*d
    
    (3d)=X/d
    X gets value X % d
    
    (4d)=X
    

    If you had the dimensions [2][2][5] you would get:

    X=9;
    
    (1d) = 9/2*5 = 0
    X = 9%10 = 9
    
    (2d) = 9/5 = 1
    X = 9%5 = 4
    
    (3d) = 4
    
    Result: [0][1][4] is the 9th element.
    

    To get from [0][1][4] to the index 9 , you do the reverse algorithm by multiplying:

    X=(1d)*b*c + (2d)*c + 3d = 0 + 1*5 +4 =9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to test what happens if my app can't get the location coordinates.
I can get easily see what projects and dlls a single project references from
Logging can get complicated, quickly. Considering that you have some code, how do you
I can get the executable location from the process, how do I get the
I can get a list of running threads from Process.GetCurrentProcess().Threads, but I need to
I can get the coordinates of a windows entire area, and the coordinates of
I can get an object if it's moused over. I can get the coordinates
How can I get xy coordinates of each gray color (R==G==B) pixel in a
I have code to get x-y coordinates when the browser scrolls: left1 = window.event.clientX
Greetings, Does anyone know how I can get coarse GPS coordinates when I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.