I am almost certain that this 'repeat' is not necessary, and that you can use broadcasting to avoid it in the next line (using something like 'a2 = a2[:, np.newaxis]')