def update_1d(a, b, length):
    a_start, a_stop, a_step = a.indices(length)
a_length = len(range(a_start, a_stop, a_step))
if a_length == 0:
    return a
b_start, b_stop, b_step = b.indices(a_length)
b_length = len(range(b_start, b_stop, b_step))
if b_length == 0:
    return slice(0, 0, 1)
start = max(0, a_start + b_start * a_step)
step = a_step * b_step
x = a_start + b_stop * a_step
if step < 0:
    stop = x if x >= 0 else None
elif a_step > 0:
    stop = min(a_stop, x)
else:
    stop = max(a_stop, x)
return slice(start, stop, step)
Срез, представляющий объединенные срезы