Round a float UP to next odd integer
You need to ceil
before dividing:
import numpy as np
def round_up_to_odd(f):
return np.ceil(f) // 2 * 2 + 1
What about:
def round_up_to_odd(f):
f = int(np.ceil(f))
return f + 1 if f % 2 == 0 else f
The idea is first to round up to an integer and then check if the integer is odd or even.