code: def shape(expr):
      """
      Return the shape of the *expr* as a tuple. *expr* should represent
      suitable object such as matrix or array.
  
      Parameters
      ==========
  
      expr : SymPy object having ``MatrixKind`` or ``ArrayKind``.
  
      Raises
      ======
  
      NoShapeError : Raised when object with wrong kind is passed.
  
      Examples
      ========
  
      This function returns the shape of any object representing matrix or array.
  
      >>> from sympy import shape, Array, ImmutableDenseMatrix, Integral
      >>> from sympy.abc import x
      >>> A = Array([1, 2])
      >>> shape(A)
      (2,)
      >>> shape(Integral(A, x))
      (2,)
      >>> M = ImmutableDenseMatrix([1, 2])
      >>> shape(M)
      (2, 1)
      >>> shape(Integral(M, x))
      (2, 1)
  
      You can support new type by dispatching.
  
      >>> from sympy import Expr
      >>> class NewExpr(Expr):
      ...     pass
      >>> @shape.register(NewExpr)
      ... def _(expr):
      ...     return shape(expr.args[0])
      >>> shape(NewExpr(M))
      (2, 1)
  
      If unsuitable expression is passed, ``NoShapeError()`` will be raised.
  
      >>> shape(Integral(x, x))
      Traceback (most recent call last):
        ...
      sympy.tensor.functions.NoShapeError: shape() called on non-array object: Integral(x, x)
  
      Notes
      =====
  
      Array-like classes (such as ``Matrix`` or ``NDimArray``) has ``shape``
      property which returns its shape, but it cannot be used for non-array
      classes containing array. This function returns the shape of any
      registered object representing array.
  
      """
      if hasattr(expr, "shape"):
          return expr.shape
      raise NoShapeError(
          "%s does not have shape, or its type is not registered to shape()."
          % expr
      )
  
file_path: sympy/sympy/tensor/functions.py
imports: from collections.abc import Iterable
  from functools import singledispatch
  from sympy.core.expr import Expr
  from sympy.core.mul import Mul
  from sympy.core.singleton import S
  from sympy.core.sympify import sympify
  from sympy.core.parameters import global_parameters
label_desc: Use image node_id 1 for calling a global function with example usage: shape(expr) and returns: expr