hourOfDay = np.mod(list(range(0, 100)), 24, dtype=np.float)
mask = np.logical_or(hourOfDay <= 7, hourOfDay >= 22)
hourOfDay[mask] = 0.4
Python, create new list based on condition applied to an existing list of same length