From: Mark Wilson Date: 2003-02-20T03:09:30+09:00 Subject: Re: 2d array? 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 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.