From: Michael Kohl Date: 2009-06-08T00:23:37+09:00 Subject: Re: adding, multiplying array On Sun, Jun 7, 2009 at 4:15 PM, Haris Bogdanović wrote: > I want to multply all elements of two arrays and add that to all elements of > the third array like this: > > c+=a*b > > c=[1,1,1] > a=[2,2,2] > b=[3,3,3] > > c=[7,7,7] # (1+2*3)=7 How about a very simple each_index approach? >> c.each_index { |i| c[i] += a[i] * b[i] } => [7, 7, 7] Hope that helps, Michael -- Blog: http://citizen428.net/ Twitter: http://twitter.com/citizen428