Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Last active October 6, 2022 15:04
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 h3ik0th/34d2921ea3981714e7bdcb80c88b71c1 to your computer and use it in GitHub Desktop.
Save h3ik0th/34d2921ea3981714e7bdcb80c88b71c1 to your computer and use it in GitHub Desktop.
def myfunc0(b, c):
r = np.sqrt(np.mean((b - c)**2))
return r
def variants(df, dftype):
dfX = df.copy()
print(dftype)
%timeit dfX["r1"] = (((dfX["B"] - dfX["C"])**2).mean())**0.5
%timeit dfX["r2"] = np.sqrt( np.mean((dfX["B"] - dfX["C"])**2))
%timeit dfX["r3"] = np.sqrt( np.mean((dfX["B"].values - dfX["C"].values)**2))
%timeit dfX["r4"] = np.sqrt( np.mean((dfX["B"].to_numpy() - dfX["C"].to_numpy())**2))
%timeit if dftype == "short:": dfX["r5"] = np.vectorize(myfunc0)(dfX["B"], dfX["C"])
variants(dfS, "short:")
variants(dfM, "medium:")
variants(dfL, "long:")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment