Does np.vectorise do the trick here? (don't worry if not, this line is perfectly readable anyway)