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 9256399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:55:52+00:00 2026-06-18T11:55:52+00:00

I have this array of arrays : array = [["z1", "y1", "x1"], ["z2", "y2",

  • 0

I have this array of arrays :

array = [["z1", "y1", "x1"], ["z2", "y2", "x2"], ["z3", "y3", "x3"], ["z4", "y4" , "x4"]]

I want to be able to retrieve elements of the array within the bigger array by an index and putting them in a variable.
For example for the index 1 the output should be :

output = [["y1"], ["y2"], ["y3"], ["y4"]]

I want also after that to be able to push these results to form a new array. In other words, I want to re-order the elements of the array (if you could find a better solution than retrieving and pushing).

Example :

output_x = [["x1"], ["x2"], ["x3"], ["x4"]]

output_y = [["y1"], ["y2"], ["y3"], ["y4"]]

output_z = [["z1"], ["z2"], ["z3"], ["z4"]]

So the final result should look like :

result = [["x1", "y1", "z1"], ["x2", "y2", "z2"], ["x3", "y3", "z3"], ["x4", "y4" , "z4"]]

I really want to find a solution for this.
Thank you

PS : x,y and z are coordinates. Forget about sorting them

  • 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-06-18T11:55:54+00:00Added an answer on June 18, 2026 at 11:55 am

    You just want Array#transpose, which is the inverse of Array#zip:

    [["z1", "y1", "x1"],
     ["z2", "y2", "x2"],
     ["z3", "y3", "x3"],
     ["z4", "y4" , "x4"]].transpose
    
    => [["z1", "z2", "z3", "z4"],
        ["y1", "y2", "y3", "y4"],
        ["x1", "x2", "x3", "x4"]]
    

    From there, it’s easy enough to split those into individual arrays. If you just want to translate the arrays into XYZ (rather than ZYX), then you may perhaps want to just map the reversed arrays:

    [["z1", "y1", "x1"],
     ["z2", "y2", "x2"],
     ["z3", "y3", "x3"],
     ["z4", "y4" , "x4"]].map(&:reverse)
    => [["x1", "y1", "z1"],
        ["x2", "y2", "z2"],
        ["x3", "y3", "z3"],
        ["x4", "y4", "z4"]] 
    

    You could also just map an arbitrary order. For example, to map from your ZYX to XZY, you would use:

    coordinates.map {|c| [c[2], c[0], c[1]] }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this very simple array which I want to be able to move
i have two arrays like this first array Array ( [0228] => Array (
I have 3 arrays like this: 1st Array ( [0695] => Array ( [loan_number]
I have arrays like this. [11] => Array ( [transactioncurrencyid] => Array ( [!name]
I have two arrays the first one has this structure Parameter Keys array array
I have an array like this: arr = [] arr[0] = "ab" arr[1] =
I have a data array like this, tourGuide: [ {"location": "london"}, {"location": "paris"}, {"location":
I have this string array(8) { [2]=> object(stdClass)#871 (2) { ["access"]=> int(0) ["value"]=> string(4)
I have two arrays with the list of images name like this array 1
Let's ets say I have two arrays: $arr1 = array("a","b","c"); $arr2 = array("1","2","3"); function

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.