def ndim(a):
    """
    Return the number of dimensions of a tensor.

    Parameters
    ----------
    a : array_like
        Input tebsir.  If it is not already a tensor, a conversion is
        attempted.

    Returns
    -------
    number_of_dimensions : int
        The number of dimensions in `a`.  Scalars are zero-dimensional.

    See Also
    --------
    ndarray.ndim : equivalent method
    shape : dimensions of tensor
    Tensor.shape : dimensions of tensor

    Examples
    --------
    >>> import mars.tensor as mt
    >>> mt.ndim([[1,2,3],[4,5,6]])
    2
    >>> mt.ndim(mt.array([[1,2,3],[4,5,6]]))
    2
    >>> mt.ndim(1)
    0

    """
    from ..datasource import asarray
    try:
        return a.ndim
    except AttributeError:
        return asarray(a).ndim
