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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:45:28+00:00 2026-06-04T08:45:28+00:00

Basically I’m working with a 2D matrix. I can access elements of the matrix

  • 0

Basically I’m working with a 2D matrix. I can access elements of the matrix by specifying an (x,y) pair to get the corresponding value at that position.

Now I also want to be able to keep track of certain pairs that are arbitrarily determined at run-time. For example, maybe I need to keep track of the values at (1,2), (3,4), and (5,6), and maybe I need to retrieve the value at that position frequently.

So I was thinking how about just make a hash .

liked_elements = {[1,2] => M[1,2], [3,4] =>M[3,4], [5,6]=>M[5,6]}

Or something like that.

Then I can quickly iterate over the hash and get the elements that I like.

Are there any issues with using arrays as hash keys?

  • 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-04T08:45:29+00:00Added an answer on June 4, 2026 at 8:45 am

    If it’s truly a matrix (an array of arrays), then you can just pass in coordinates like this

    matrix = [[:a, :b, :c],[:d, :e, :f], [:g, :h, :i]]
    matrix[0][1] # returns :b
    matrix[1][2] # returns :f
    matrix[2][3] # returns nil, since 3 is out of bounds
    

    Yes, you can create an array as a hash key.

    h = Hash[[0,1], matrix[0][1]]
    h[[0,1]] # returns :b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically this function is meant to store the height value of the element that
basically I have a function that resizes elements accordingly with jquery triggering the function
Basically, I would like a brief explanation of how I can access a SQL
Basically I'm making a filter for my portfolio so that you can click on
Basically I have some variables that I don't want to preinitialize: originalTime = None
basically i have (state, state code) pairs, that are subsets of country [USA] ->
Basically what I need to do is write a function that takes in a
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically, I have a main page (parent page) with a link that opens up

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.