Just Another Victim of the Ambient M. 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]]
end
end
Yes, this works as expected. Easy enough to add if you really want it.