I agree it is not the prettiest. The one advantage of this method is that it doesn't require that k and n have the same shape. It lets the numpy functions take care of all the broadcasting, so we don't have to try to replicate numpy broadcasting at the beginning.