You can write this as:

```
@property
def ndim(self):
  return len(self.shape)
```