Matrix in Ruby

M

Minkoo Seo

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 Seo
 
A

ara.t.howard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top