rubyでaccumulate-nを作ってみた
module Enumerable def accumulate_n(init) (0..self.first.size-1).inject([]) do |result, i| x = self.map{ |e| e[i]} result << x.inject(init){ |re,e| yield(re,e)} end end end a = (0..3).map{ |e| e * 3}.map{ |e| [e,e+1,e+2]} a # => [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]] a.accumulate_n(0){ |re,e| re + e} # => [18, 22, 26] a # => [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]