Yes, just use `x.ndim` here, no need to make an additional `dim` variable.