Tried to optimize second_window function.

Used a deque for the sliding window in which we're calculating the min and max. Used np.ndarray.item to read more efficiently an item from a numpy array, and np.ma.put to write more efficiently to a numpy masked array. No need in the loop to check for masked data, as we are working on unmasked slices anyway.