```Tomasz Wegrzanowski wrote:
>
> Well, it's a very small thing, but tripple-dot makes is somewhat more

Good point.

>  sum_x = Array.new(x.size){0.0}
>  sum_x_sq = Array.new(x.size){0.0}
>  for i in 0..x.size-1
>    sum_x[i]    = x[i].inject(0) { |sum, e| sum + e }
>    sum_x_sq[i] = x[i].inject(0) { |sum, e| sum + e**2 }
>  end
> can be rewritten to:
>  sum_x = (0...x.size).map{|i| x[i].inject(0) { |sum, e| sum + e }}
>  sum_x_sq = (0...x.size).map{|i| x[i].inject(0) { |sum, e| sum + e**2 }}
> which looks a lot neater imho.

Agreed.

How about the (i,j) beasts?   E.g.,

sum_xy = Array.new(x.size){ Array.new(y.size){0.0} }
for k in 0..n-1
for i in 0...x.size
for j in 0...y.size
sum_xy[i][j] += x[i][k]*y[j][k]
end
end
end

Doubly embedded maps?

Is there anyway to do all this without using indices?

Maybe intercept the incoming vectors, build /scalar/
correlations for each variable combination, and then
assemble the final /matrix/ of correlations?

> It would look even neater to write:
>  sum_x = x.map{|xi| xi.sum}
>  sum_x_sj = x.map{|xi| xi.map{|e|e**2}.sum}
> but Ruby doesn't have Enumerable#sum by default.

Agreed.  I'm happy to locally extend Enumerable...

module Enumerable
def sum
self.inject(0){ |sum,e| sum + e }
end
end

> Oh well, you have a few ideas of making the code nicer now :-)

Yes.  Thanks.

Regards,
--
Bil
http://fun3d.larc.nasa.gov

```