From: Paul Lutus Date: 2006-09-11T12:00:23+09:00 Subject: Re: Matrix Just Another Victim of the Ambient Morality wrote: / ... >> You can only set an arbitrary element of a Matrix when it is created. >> Once created, you can't change any of the entries. > > The []= operator does seem conspicuously missing. If anyone knows why > this was (obviously) deliberately left out, please say something! Matrices are meant to be operated on as units, not by manipulating the contents of individual cells. Think of a matrix as a datatype, a complete, self-contained entity, one you can create or destroy in its entirety. BTW, in answer to an earlier question: > a) Is there a way to create a non-square matrix in ruby? #! /usr/bin/ruby require 'matrix' m = Matrix[[1,2,3],[4,5,6],[7,8,9]] nsqm = Matrix[[1,2,3],[7,8,9]] puts m,nsqm Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]] Matrix[[1, 2, 3], [7, 8, 9]] > > Of course, if this is useful to you, you can always add it, yourself! > I think it would go something like this... > > > require 'matrix' > > class Matrix # are for kids! > def []= (i, j, v) > @rows[i][j] = v > end > end Yes, this works as expected. Easy enough to add if you really want it. :) -- Paul Lutus http://www.arachnoid.com