Created
May 17, 2021 19:43
-
-
Save rat-h/f29a5deb096e0c50095d66cfcad953c6 to your computer and use it in GitHub Desktop.
Get roots of seqence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_roots(x,y): | |
''' | |
Thanks to ImportanceOfBeingErnest | |
https://stackoverflow.com/a/46911822/1887559 | |
''' | |
s = np.abs(np.diff(np.sign(y))).astype(bool) | |
return x[:-1][s] + np.diff(x)[s]/(np.abs(y[1:][s]/y[:-1][s])+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment