change a loop to a dot product