Skip to content

Instantly share code, notes, and snippets.

@vegarsti
Last active September 6, 2017 11:33
Show Gist options
  • Save vegarsti/df4068bd3701b2b397f7c68cbeadad50 to your computer and use it in GitHub Desktop.
Save vegarsti/df4068bd3701b2b397f7c68cbeadad50 to your computer and use it in GitHub Desktop.
# defaultdict use case
# Finding a Pareto front, where (x1, x2) is a list of tuples satisfying
# e.g. (x1, x2) : |df[(df[var1 > x1]) & df[var2 > x2)]| < 0.1|df|,
# where |df| is the size of df, i.e., df.shape[0] (in Pandas)
pareto = defaultdict(lambda: np.Inf)
for x1, x2 in xs:
pareto[x1] = min(pareto[x1], x2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment