def matrix_power(x, n, name=None):
    "\n    Computes the n-th power of a square matrix or a batch of square matrices.\n\n    Let :math:`X` be a sqaure matrix or a batch of square matrices, :math:`n` be\n    an exponent, the equation should be:\n\n    .. math::\n        Out = X ^ {n}\n\n    Specifically,\n\n    - If `n > 0`, it returns the matrix or a batch of matrices raised to the power\n    of `n`.\n\n    - If `n = 0`, it returns the identity matrix or a batch of identity matrices.\n\n    - If `n < 0`, it returns the inverse of each matrix (if invertible) raised to\n    the power of `abs(n)`.\n\n    Args:\n        x (Tensor): A square matrix or a batch of square matrices to be raised\n            to power `n`. Its shape should be `[*, M, M]`, where `*` is zero or\n            more batch dimensions. Its data type should be float32 or float64.\n        n (int): The exponent. It can be any positive, negative integer or zero.\n        name (str, optional): Name for the operation (optional, default is None).\n            For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tensor: The n-th power of the matrix (or the batch of matrices) `x`. Its\n            data type should be the same as that of `x`.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n\n            x = paddle.to_tensor([[1, 2, 3],\n                                  [1, 4, 9],\n                                  [1, 8, 27]], dtype='float64')\n            print(paddle.linalg.matrix_power(x, 2))\n            # [[6.  , 34. , 102.],\n            #  [14. , 90. , 282.],\n            #  [36. , 250., 804.]]\n\n            print(paddle.linalg.matrix_power(x, 0))\n            # [[1., 0., 0.],\n            #  [0., 1., 0.],\n            #  [0., 0., 1.]]\n\n            print(paddle.linalg.matrix_power(x, -2))\n            # [[ 12.91666667, -12.75000000,  2.83333333 ],\n            #  [-7.66666667 ,  8.         , -1.83333333 ],\n            #  [ 1.80555556 , -1.91666667 ,  0.44444444 ]]\n    "
    if paddle.in_dynamic_mode():
        return _C_ops.matrix_power(x, 'n', n)
    check_variable_and_dtype(x, 'dtype', ['float32', 'float64'], 'matrix_power')
    check_type(n, 'n', int, 'matrix_power')
    helper = LayerHelper('matrix_power', **locals())
    out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='matrix_power', inputs={'X': x}, outputs={'Out': out}, attrs={'n': n})
    return out
Computes the n-th power of a square matrix or a batch of square matrices.

Let :math:`X` be a sqaure matrix or a batch of square matrices, :math:`n` be
an exponent, the equation should be:

.. math::
    Out = X ^ {n}

Specifically,

- If `n > 0`, it returns the matrix or a batch of matrices raised to the power
of `n`.

- If `n = 0`, it returns the identity matrix or a batch of identity matrices.

- If `n < 0`, it returns the inverse of each matrix (if invertible) raised to
the power of `abs(n)`.

Args:
    x (Tensor): A square matrix or a batch of square matrices to be raised
        to power `n`. Its shape should be `[*, M, M]`, where `*` is zero or
        more batch dimensions. Its data type should be float32 or float64.
    n (int): The exponent. It can be any positive, negative integer or zero.
    name (str, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: The n-th power of the matrix (or the batch of matrices) `x`. Its
        data type should be the same as that of `x`.

Examples:
    .. code-block:: python

        import paddle

        x = paddle.to_tensor([[1, 2, 3],
                              [1, 4, 9],
                              [1, 8, 27]], dtype='float64')
        print(paddle.linalg.matrix_power(x, 2))
        # [[6.  , 34. , 102.],
        #  [14. , 90. , 282.],
        #  [36. , 250., 804.]]

        print(paddle.linalg.matrix_power(x, 0))
        # [[1., 0., 0.],
        #  [0., 1., 0.],
        #  [0., 0., 1.]]

        print(paddle.linalg.matrix_power(x, -2))
        # [[ 12.91666667, -12.75000000,  2.83333333 ],
        #  [-7.66666667 ,  8.         , -1.83333333 ],
        #  [ 1.80555556 , -1.91666667 ,  0.44444444 ]]
def matrix_power(x, n, name=None):
    "\n    Computes the n-th power of a square matrix or a batch of square matrices.\n\n    Let :math:`X` be a sqaure matrix or a batch of square matrices, :math:`n` be\n    an exponent, the equation should be:\n\n    .. math::\n        Out = X ^ {n}\n\n    Specifically,\n\n    - If `n > 0`, it returns the matrix or a batch of matrices raised to the power\n    of `n`.\n\n    - If `n = 0`, it returns the identity matrix or a batch of identity matrices.\n\n    - If `n < 0`, it returns the inverse of each matrix (if invertible) raised to\n    the power of `abs(n)`.\n\n    Args:\n        x (Tensor): A square matrix or a batch of square matrices to be raised\n            to power `n`. Its shape should be `[*, M, M]`, where `*` is zero or\n            more batch dimensions. Its data type should be float32 or float64.\n        n (int): The exponent. It can be any positive, negative integer or zero.\n        name (str, optional): Name for the operation (optional, default is None).\n            For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tensor: The n-th power of the matrix (or the batch of matrices) `x`. Its\n            data type should be the same as that of `x`.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n\n            x = paddle.to_tensor([[1, 2, 3],\n                                  [1, 4, 9],\n                                  [1, 8, 27]], dtype='float64')\n            print(paddle.linalg.matrix_power(x, 2))\n            # [[6.  , 34. , 102.],\n            #  [14. , 90. , 282.],\n            #  [36. , 250., 804.]]\n\n            print(paddle.linalg.matrix_power(x, 0))\n            # [[1., 0., 0.],\n            #  [0., 1., 0.],\n            #  [0., 0., 1.]]\n\n            print(paddle.linalg.matrix_power(x, -2))\n            # [[ 12.91666667, -12.75000000,  2.83333333 ],\n            #  [-7.66666667 ,  8.         , -1.83333333 ],\n            #  [ 1.80555556 , -1.91666667 ,  0.44444444 ]]\n    "
    if paddle.in_dynamic_mode():
        return _C_ops.matrix_power(x, 'n', n)
    check_variable_and_dtype(x, 'dtype', ['float32', 'float64'], 'matrix_power')
    check_type(n, 'n', int, 'matrix_power')
    helper = LayerHelper('matrix_power', **locals())
    out = helper.create_variable_for_type_inference(dtype=x.dtype)
    helper.append_op(type='matrix_power', inputs={'X': x}, outputs={'Out': out}, attrs={'n': n})
    return out