Matrix in Ruby


#1

What is the best way to create a matrix whose size is m x n?
The value of m and n may be different, and the values in each cell
should be zeroed.

Can anybody help me?

Sincerely,
Minkoo S.


#2

I’ve found it by myself:

a = Matrix[(0…3).map { Array.new(5) }]


#3

On Sat, 11 Mar 2006, Minkoo S. wrote:

I’ve found it by myself:

a = Matrix[(0…3).map { Array.new(5) }]

if you’re going to be working with large matrices and doing lots of
number
crunching you’ll want

require ‘narray’

a = NArray.int 3, 5

it’s on the raa.

cheers.

-a