Returns the rank of this shape, or None if it is unspecified.

def ndims(self):
        """Returns the rank of this shape, or None if it is unspecified."""
        if self._dims is None:
            return None
        else:
            if self._ndims is None:
                self._ndims = len(self._dims)
            return self._ndims