# 2d array?

**URL:** <https://rubytalk.org/t/2d-array/4806>\
**Category:** ruby-talk\
**Created:** [19 February 2003 15:23 UTC](https://rubytalk.org/t/2d-array/4806 "2003-02-19T15:23:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Garriss1](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Michael\_Garriss1](https://rubytalk.org/u/Michael_Garriss1)\
**Post date:** [19 February 2003 15:23 UTC](https://rubytalk.org/t/2d-array/4806/1 "2003-02-19T15:23:12Z")

</div>

Sorry, new to ruby. Does ruby have a 2d array? If so, where could I  
find the documentation?

TIA,  
Michael Garriss

---

<div class="post-metadata">

**Author:** ![Armin\_Roehrl](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Armin\_Roehrl](https://rubytalk.org/u/Armin_Roehrl)\
**Post date:** [19 February 2003 15:28 UTC](https://rubytalk.org/t/2d-array/4806/2 "2003-02-19T15:28:44Z")

</div>

> Sorry, new to ruby. Does ruby have a 2d array? If so, where could I  
> find the documentation?  
> One possibility is to put Arrays in Arrays. This way you can  
> create n-d Arrays. Here is a 2-d array.

irb(main):001:0\> t=[[1,2,3],[4,5,6],[7,8,9]]  
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]  
irb(main):002:0\> t[0][1]  
2  
irb(main):003:0\>

Maybe you also want to use at matrix, which by  
definition is a 2d array.

Good luck,  
-A.

> **···**
>
> * * *
> 
> Armin Roehrl, [http://www.approximity.com](http://www.approximity.com)  
> We manage risk
> 
> We cannot solve our problems with the same thinking we used when we created  
> them.  
> – Albert Einstein

---

<div class="post-metadata">

**Author:** ![Mark\_Wilson](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mark\_Wilson](https://rubytalk.org/u/Mark_Wilson)\
**Post date:** [19 February 2003 18:09 UTC](https://rubytalk.org/t/2d-array/4806/3 "2003-02-19T18:09:30Z")

</div>

I think Armin’s reference to ‘at matrix’ is a reference to matrix.rb,  
which is a Matrix class that is part of the Ruby standard distribution.  
matrix.rb is a port of smalltalk’s matrix class and includes finding  
methods (rank, determinant, etc.) and transformation methods (such as  
transposition).

Mark Slagell’s book, “Teach Yourself Ruby”, includes a chapter that  
walks through creating an integer matrix with a number of useful  
methods.

Also, a 2d array (a matrix) can be of any dimension in mathematical  
terms, represented by a ‘table’ of ordered rows and columns.

> **···**
>
> On Wednesday, February 19, 2003, at 10:28 AM, Armin Roehrl wrote:
> 
> > > Sorry, new to ruby. Does ruby have a 2d array? If so, where could I  
> > > find the documentation?  
> > > One possibility is to put Arrays in Arrays. This way you can  
> > > create n-d Arrays. Here is a 2-d array.
> > 
> > irb(main):001:0\> t=[[1,2,3],[4,5,6],[7,8,9]]  
> > [[1, 2, 3], [4, 5, 6], [7, 8, 9]]  
> > irb(main):002:0\> t[0][1]  
> > 2  
> > irb(main):003:0\>
> > 
> > Maybe you also want to use at matrix, which by  
> > definition is a 2d array.
> > 
> > ## Good luck, -A.
> > 
> > Armin Roehrl, [http://www.approximity.com](http://www.approximity.com)
