rolled for loop into numpy procedures