Skip to content

Instantly share code, notes, and snippets.

@rkennesson
Created September 6, 2019 07:51
Show Gist options
  • Save rkennesson/c7af72e2f0fcb3c23c18dd2726a2a497 to your computer and use it in GitHub Desktop.
Save rkennesson/c7af72e2f0fcb3c23c18dd2726a2a497 to your computer and use it in GitHub Desktop.
def my_round(x, prec=2, base=0.05): return (base * (np.array(x) / base).round()).round(prec)
@rkennesson
Copy link
Author

For rounding to non-integer values, such as 0.05:

def myround(x, prec=2, base=.05):
return round(base * round(float(x)/base),prec)
I found

@rkennesson
Copy link
Author

x // base * base

@rkennesson
Copy link
Author

math.ceil((math.floor(math.log(256,2)+1))/8)*8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment