Generalized Reduced Gradient Method Python