Added the Python implementation of the matlab code