From: ibotty Date: 2003-08-31T07:03:50+09:00 Subject: Re: multiply all array with array >>>> a = [1,2,3] and b = [4,5,6] >>>> and i want to get another array, with c[ix] = a[ix] * b[ix]. >>>> (i want to get c = [4,10,18]) >>> a.zip(b).map {|i, j| i*j} >> But isn't that the wrong answer? >> [...] >> And if you meant the dot product rather than the cross >> product, you would get a scalar. > I think this is what the original poster wanted. He doesn't > seem to be asking for a cross product OR a dot product as > far as I can tell, but just a nice idiomatic way of doing > a specific operation. we do have a Vector (defined in matrix.rb (in 1.6 at least)) this Vector should define cross and dot product (well, cross product it should not necessarily define, too much specific to three dimension vectors, huh? ;) so in short, i think this a product of two arrays should not be a cross or dot product. never. use a vector instead, if you want to. btw: this is not meant to be rude, but why put something in array, when it belongs to something else. ~ibotty