Change Matlab Code To Python