I think this could be simplify

``` python 
if np.all(dx < 0):
    direction = -1
else:
    raise ValueError("...")

````