Skip to content

Instantly share code, notes, and snippets.

@rat-h
Created May 17, 2021 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rat-h/f29a5deb096e0c50095d66cfcad953c6 to your computer and use it in GitHub Desktop.
Save rat-h/f29a5deb096e0c50095d66cfcad953c6 to your computer and use it in GitHub Desktop.
Get roots of seqence
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