This line is probably clearer as `if shape == () or shape == ((),)`? Or even
```
if len(shape) == 1 and isinstance(shape[0], tuple):
    shape = shape[0]
if shape == ():
```