Ruby 2.1.0 リファレンスマニュアル > ライブラリ一覧 > matrixライブラリ > Matrixクラス > collect

instance method Matrix#collect

map {|x| ... } -> Matrix[permalink][rdoc]
collect {|x| ... } -> Matrix
map -> Enumerator
collect -> Enumerator

行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。

ブロックがない場合、 Enumerator を返します。



require 'matrix'

m = Matrix[[1, 2], [3, 4]]
p m.map { |x| x + 100 } # => Matrix[[101, 102], [103, 104]]

[SEE_ALSO] Matrix#each