python redo of my Octave script - not tested, yet