From: Daniel DeLorme Date: 2006-07-05T14:17:56+09:00 Subject: Re: Parallel Array Nasir Khan wrote: > If I have two arrays a=[1,1,1,1] and b=[2,2,2,2] and I want to add each > element up, something like - > > c = a plus b => [3,3,3,3] > > One way I could think up is - > > irb(main):010:0> (0...a.length).collect{|k| a[k]+b[k]} > => [3, 3, 3, 3] > > Is there a better/faster way? I'm not sure about faster, but this is probably more readable: irb(main):001:0> require "matrix" => true irb(main):002:0> Vector[1,1,1,1] + Vector[2,2,2,2] => Vector[3, 3, 3, 3] Daniel