singleton method Matrix.build

build(row_size, column_size = row_size) {|row, col| ... } -> Matrix[permalink][rdoc][edit]
build(row_size, column_size = row_size) -> Enumerable

row_size×column_sizeの行列をブロックの返り値から生成します。

行列の各要素の位置がブロックに渡され、それの返り値が行列の要素となります。

ブロックを省略した場合は Enumerator を返します。



require 'matrix'
m = Matrix.build(2, 4) {|row, col| col - row }
  # => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
m = Matrix.build(3) { rand }
  # => a 3x3 matrix with random elements
[PARAM] row_size:
行列の行数
[PARAM] column_size:
行列の列数