Mapping values from two array in Ruby
The Array.zip function does an elementwise combination of arrays. It's not quite as clean as the Python syntax, but here's one approach you could use:
weights = [1, 2, 3]data = [4, 5, 6]result = Array.newa.zip(b) { |x, y| result << x * y } # For just the one operationsum = 0a.zip(b) { |x, y| sum += x * y } # For both operations