require 'matrix' Matrix.I(3) #=> Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]] Matrix[[0,1],[2,0]] * Vector[1.2,3.4] #=> Vector[3.4, 2.4]
mv mdarray.c mdarray.c.bak ruby (ruby_unpacked_dir)/sample/rename.rb mdarray.c.bak > mdarray.c ruby -r mkmf -e 'create_makefile("mdarray")' make
a = Array.new(2,Array.new(2)) #=> [[nil, nil], [nil, nil]] a[0][0] = 1 p a #=> [[1, nil], [1, nil]]
case: 2-D
class Array2D < Array def [](n) self[n]=Array.new if super(n)==nil super(n) end end a = Array2D.new a[2][2] = "foo" #=> [nil, nil, [nil, nil, "foo"]]
case: Multi-D
class ArrayMD < Array def [](n) self[n]=ArrayMD.new if super(n)==nil super(n) end end a = ArrayMD.new a[1][2][3]="foo" #=> [nil, [nil, nil, [nil, nil, nil, "foo"]]]