From: Victor Reyes Date: 2007-10-20T10:59:20+09:00 Subject: Re: 2 dimensional array ------=_Part_4881_12426651.1192845562367 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I just wanted to play with Magic Squares and other multidimensional arrays. Thank you for the info about matrix. On 10/19/07, Todd Benson wrote: > > On 10/19/07, Victor Reyes wrote: > > Sorry guys, I am very slow. > > In conclusion. how would the following be represented in Ruby? > > It is a 3x3 matrix. > > > > 11 76 -34 31 -66 71 -1 63 34 > > Thank you > > It depends on what you want to do. If you just want to represent it > as a nested array, you could... > > my_matrix = [[11, 76, -34], [31, -66, 71], [-1 63 34]] > > As you notice, this is still 2-dimensional. > > > For math type matrix functionality, there is the matrix standard > library... > > require 'matrix' > > which includes methods that return a manipulated matrix (represented > by the Matrix object), like inverse, rank, determinant, algebraic > functions, etc. I believe you can also go back and forth between > nested arrays and Matrix objects using Matrix#to_a and > Matrix#[](*rows). Somebody else might be able to fill you in better. > > You can find documentation for that under the standard library docs at > http://www.ruby-doc.org. > > hth, > Todd > > ------=_Part_4881_12426651.1192845562367--