Solve Matrix in python