def norm(x, p='fro', axis=None, keepdim=False, name=None):
    "\n\n    Returns the matrix norm (Frobenius) or vector norm (the 1-norm, the Euclidean\n    or 2-norm, and in general the p-norm for p > 0) of a given tensor.\n\n    .. note::\n        This norm API is different from `numpy.linalg.norm`.\n        This api supports high-order input tensors (rank >= 3), and certain axis need to be pointed out to calculate the norm.\n        But `numpy.linalg.norm` only supports 1-D vector or 2-D matrix as input tensor.\n        For p-order matrix norm, this api actually treats matrix as a flattened vector to calculate the vector norm, NOT REAL MATRIX NORM.\n\n    Args:\n        x (Tensor): The input tensor could be N-D tensor, and the input data\n            type could be float32 or float64.\n        p (float|string, optional): Order of the norm. Supported values are `fro`, `0`, `1`, `2`,\n            `inf`, `-inf` and any positive real number yielding the corresponding p-norm. Not supported: ord < 0 and nuclear norm.\n            Default value is `fro`.\n        axis (int|list|tuple, optional): The axis on which to apply norm operation. If axis is int\n            or list(int)/tuple(int)  with only one element, the vector norm is computed over the axis.\n            If `axis < 0`, the dimension to norm operation is rank(input) + axis.\n            If axis is a list(int)/tuple(int) with two elements, the matrix norm is computed over the axis.\n            Defalut value is `None`.\n        keepdim (bool, optional): Whether to reserve the reduced dimension in the\n            output Tensor. The result tensor will have fewer dimension\n            than the :attr:`input` unless :attr:`keepdim` is true, default\n            value is False.\n        name (str, optional): The default value is None. Normally there is no need for\n            user to set this property. For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tensor: results of norm operation on the specified axis of input tensor,\n        it's data type is the same as input's Tensor.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n            import numpy as np\n            shape=[2, 3, 4]\n            np_input = np.arange(24).astype('float32') - 12\n            np_input = np_input.reshape(shape)\n            x = paddle.to_tensor(np_input)\n            #[[[-12. -11. -10.  -9.] [ -8.  -7.  -6.  -5.] [ -4.  -3.  -2.  -1.]]\n            # [[  0.   1.   2.   3.] [  4.   5.   6.   7.] [  8.   9.  10.  11.]]]\n\n            # compute frobenius norm along last two dimensions.\n            out_fro = paddle.linalg.norm(x, p='fro', axis=[0,1])\n            # out_fro.numpy() [17.435596 16.911535 16.7332   16.911535]\n\n            # compute 2-order vector norm along last dimension.\n            out_pnorm = paddle.linalg.norm(x, p=2, axis=-1)\n            #out_pnorm.numpy(): [[21.118711  13.190906   5.477226]\n            #                    [ 3.7416575 11.224972  19.131126]]\n\n            # compute 2-order  norm along [0,1] dimension.\n            out_pnorm = paddle.linalg.norm(x, p=2, axis=[0,1])\n            #out_pnorm.numpy(): [17.435596 16.911535 16.7332   16.911535]\n\n            # compute inf-order  norm\n            out_pnorm = paddle.linalg.norm(x, p=np.inf)\n            #out_pnorm.numpy()  = [12.]\n            out_pnorm = paddle.linalg.norm(x, p=np.inf, axis=0)\n            #out_pnorm.numpy(): [[12. 11. 10. 9.] [8. 7. 6. 7.] [8. 9. 10. 11.]]\n\n            # compute -inf-order  norm\n            out_pnorm = paddle.linalg.norm(x, p=-np.inf)\n            #out_pnorm.numpy(): [0.]\n            out_pnorm = paddle.linalg.norm(x, p=-np.inf, axis=0)\n            #out_pnorm.numpy(): [[0. 1. 2. 3.] [4. 5. 6. 5.] [4. 3. 2. 1.]]\n    "

    def frobenius_norm(input, dim=None, keepdim=False, name=None):
        '\n        The frobenius norm OP is to calculate the frobenius norm of certain two dimensions of Tensor `input`.\n        Args:\n          input (Variable): Tensor, data type float32, float64.\n          dim (list, optional): None for last two dimensions.\n          keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.\n        '
        if ((dim is not None) and (not (isinstance(dim, list) and (len(dim) == 2)))):
            raise ValueError('The dim of frobenius norm op should be None or two elements list!')
        if paddle.in_dynamic_mode():
            if (dim is None):
                return _C_ops.frobenius_norm(input, 'keep_dim', keepdim, 'reduce_all', True)
            return _C_ops.frobenius_norm(input, 'dim', dim, 'keep_dim', keepdim, 'reduce_all', False)
        attrs = {'dim': dim, 'keep_dim': keepdim, 'reduce_all': False}
        if (dim is None):
            attrs['reduce_all'] = True
        check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'frobenius_norm')
        helper = LayerHelper('frobenius_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='frobenius_norm', inputs={'X': input}, outputs={'Out': out}, attrs=attrs)
        return out

    def vector_norm(input, porder=None, axis=None, keepdim=False, asvector=False, name=None):
        '\n        Calculate the p-order vector norm for certain  dimension of Tensor `input`.\n        Args:\n          input (Variable): Tensor, data type float32, float64.\n          porder (float, optional): None for porder=2.0.\n          axis (int, optional): None for last dimension.\n          keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.\n        '
        if paddle.in_dynamic_mode():
            if (axis is None):
                axis = (- 1)
            return _C_ops.p_norm(input, 'porder', porder, 'axis', axis, 'keepdim', keepdim, 'asvector', asvector)
        if (porder is not None):
            check_type(porder, 'porder', (float, int), 'p_norm')
        if (axis is not None):
            check_type(axis, 'axis', int, 'p_norm')
        check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'p_norm')
        attrs = {'axis': (axis if (axis is not None) else (- 1)), 'porder': (float(porder) if (porder is not None) else 2.0), 'keepdim': keepdim, 'asvector': asvector, 'epsilon': 1e-12}
        helper = LayerHelper('p_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='p_norm', inputs={'X': input}, outputs={'Out': out}, attrs=attrs)
        return out

    def inf_norm(input, porder=None, axis=axis, keepdim=False, asvector=False, name=None):
        helper = LayerHelper('frobenius_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='abs', inputs={'X': input}, outputs={'Out': out})
        reduce_out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        reduce_all = (True if ((axis == None) or (axis == []) or (asvector == True)) else False)
        axis = (axis if ((axis != None) and (axis != [])) else [0])
        reduce_type = ('reduce_max' if (porder == np.float('inf')) else 'reduce_min')
        helper.append_op(type=reduce_type, inputs={'X': out}, outputs={'Out': reduce_out}, attrs={'dim': axis, 'keep_dim': keepdim, 'reduce_all': reduce_all})
        return reduce_out

    def p_matrix_norm(input, porder=1.0, axis=axis, keepdim=False, name=None):
        '\n        NOTE:\n            This function actually treats the matrix as flattened vector to calculate vector norm instead of matrix norm.\n        '
        block = LayerHelper('norm', **locals())
        out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        abs_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='abs', inputs={'X': input}, outputs={'Out': abs_out})
        pow_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='pow', inputs={'X': abs_out}, outputs={'Out': pow_out}, attrs={'factor': porder})
        sum_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='reduce_sum', inputs={'X': pow_out}, outputs={'Out': sum_out}, attrs={'dim': axis, 'keep_dim': keepdim, 'reduce_all': (True if (axis is None) else False)})
        porder
        block.append_op(type='pow', inputs={'X': sum_out}, outputs={'Out': out}, attrs={'factor': float((1.0 / porder))})
        return out
    if ((axis is None) and (p is not None)):
        if isinstance(p, str):
            if (p == 'fro'):
                return frobenius_norm(x, dim=axis, keepdim=keepdim, name=name)
            else:
                raise ValueError("only valid string values are 'fro', found {}".format(p))
        elif isinstance(p, (int, float)):
            return vector_norm(x, porder=p, axis=axis, keepdim=keepdim, asvector=True, name=name)
        else:
            raise ValueError('only valid p type is string or float, found {}'.format(type(p)))
    if isinstance(axis, tuple):
        axis = list(axis)
    if (isinstance(axis, list) and (len(axis) == 1)):
        axis = axis[0]
    if isinstance(axis, int):
        if isinstance(p, str):
            if (p == 'fro'):
                return vector_norm(x, porder=2, axis=axis, keepdim=keepdim, asvector=False, name=name)
            else:
                raise ValueError("only valid string values are 'fro', found {}".format(p))
        elif isinstance(p, (int, float)):
            return vector_norm(x, axis=axis, porder=p, keepdim=keepdim, asvector=False, name=name)
        else:
            raise ValueError('unspport p for p-order vector norm. except float, found {}'.format(p))
    elif (isinstance(axis, list) and (len(axis) == 2)):
        if (p == 'fro'):
            return frobenius_norm(x, dim=axis, keepdim=keepdim, name=name)
        elif ((p == np.inf) or (p == (- np.inf))):
            return inf_norm(x, porder=p, axis=axis, keepdim=keepdim, name=name)
        elif (p == 0):
            raise ValueError('just suport axis type int or list (length of list <=1) if p = 0, found {}'.format(axis))
        else:
            return p_matrix_norm(x, porder=p, axis=axis, keepdim=keepdim, name=name)
    else:
        raise ValueError('except axis type int or list (length of list <=2), found {}'.format(axis))
Returns the matrix norm (Frobenius) or vector norm (the 1-norm, the Euclidean
or 2-norm, and in general the p-norm for p > 0) of a given tensor.

.. note::
    This norm API is different from `numpy.linalg.norm`.
    This api supports high-order input tensors (rank >= 3), and certain axis need to be pointed out to calculate the norm.
    But `numpy.linalg.norm` only supports 1-D vector or 2-D matrix as input tensor.
    For p-order matrix norm, this api actually treats matrix as a flattened vector to calculate the vector norm, NOT REAL MATRIX NORM.

Args:
    x (Tensor): The input tensor could be N-D tensor, and the input data
        type could be float32 or float64.
    p (float|string, optional): Order of the norm. Supported values are `fro`, `0`, `1`, `2`,
        `inf`, `-inf` and any positive real number yielding the corresponding p-norm. Not supported: ord < 0 and nuclear norm.
        Default value is `fro`.
    axis (int|list|tuple, optional): The axis on which to apply norm operation. If axis is int
        or list(int)/tuple(int)  with only one element, the vector norm is computed over the axis.
        If `axis < 0`, the dimension to norm operation is rank(input) + axis.
        If axis is a list(int)/tuple(int) with two elements, the matrix norm is computed over the axis.
        Defalut value is `None`.
    keepdim (bool, optional): Whether to reserve the reduced dimension in the
        output Tensor. The result tensor will have fewer dimension
        than the :attr:`input` unless :attr:`keepdim` is true, default
        value is False.
    name (str, optional): The default value is None. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: results of norm operation on the specified axis of input tensor,
    it's data type is the same as input's Tensor.

Examples:
    .. code-block:: python

        import paddle
        import numpy as np
        shape=[2, 3, 4]
        np_input = np.arange(24).astype('float32') - 12
        np_input = np_input.reshape(shape)
        x = paddle.to_tensor(np_input)
        #[[[-12. -11. -10.  -9.] [ -8.  -7.  -6.  -5.] [ -4.  -3.  -2.  -1.]]
        # [[  0.   1.   2.   3.] [  4.   5.   6.   7.] [  8.   9.  10.  11.]]]

        # compute frobenius norm along last two dimensions.
        out_fro = paddle.linalg.norm(x, p='fro', axis=[0,1])
        # out_fro.numpy() [17.435596 16.911535 16.7332   16.911535]

        # compute 2-order vector norm along last dimension.
        out_pnorm = paddle.linalg.norm(x, p=2, axis=-1)
        #out_pnorm.numpy(): [[21.118711  13.190906   5.477226]
        #                    [ 3.7416575 11.224972  19.131126]]

        # compute 2-order  norm along [0,1] dimension.
        out_pnorm = paddle.linalg.norm(x, p=2, axis=[0,1])
        #out_pnorm.numpy(): [17.435596 16.911535 16.7332   16.911535]

        # compute inf-order  norm
        out_pnorm = paddle.linalg.norm(x, p=np.inf)
        #out_pnorm.numpy()  = [12.]
        out_pnorm = paddle.linalg.norm(x, p=np.inf, axis=0)
        #out_pnorm.numpy(): [[12. 11. 10. 9.] [8. 7. 6. 7.] [8. 9. 10. 11.]]

        # compute -inf-order  norm
        out_pnorm = paddle.linalg.norm(x, p=-np.inf)
        #out_pnorm.numpy(): [0.]
        out_pnorm = paddle.linalg.norm(x, p=-np.inf, axis=0)
        #out_pnorm.numpy(): [[0. 1. 2. 3.] [4. 5. 6. 5.] [4. 3. 2. 1.]]
def norm(x, p='fro', axis=None, keepdim=False, name=None):
    "\n\n    Returns the matrix norm (Frobenius) or vector norm (the 1-norm, the Euclidean\n    or 2-norm, and in general the p-norm for p > 0) of a given tensor.\n\n    .. note::\n        This norm API is different from `numpy.linalg.norm`.\n        This api supports high-order input tensors (rank >= 3), and certain axis need to be pointed out to calculate the norm.\n        But `numpy.linalg.norm` only supports 1-D vector or 2-D matrix as input tensor.\n        For p-order matrix norm, this api actually treats matrix as a flattened vector to calculate the vector norm, NOT REAL MATRIX NORM.\n\n    Args:\n        x (Tensor): The input tensor could be N-D tensor, and the input data\n            type could be float32 or float64.\n        p (float|string, optional): Order of the norm. Supported values are `fro`, `0`, `1`, `2`,\n            `inf`, `-inf` and any positive real number yielding the corresponding p-norm. Not supported: ord < 0 and nuclear norm.\n            Default value is `fro`.\n        axis (int|list|tuple, optional): The axis on which to apply norm operation. If axis is int\n            or list(int)/tuple(int)  with only one element, the vector norm is computed over the axis.\n            If `axis < 0`, the dimension to norm operation is rank(input) + axis.\n            If axis is a list(int)/tuple(int) with two elements, the matrix norm is computed over the axis.\n            Defalut value is `None`.\n        keepdim (bool, optional): Whether to reserve the reduced dimension in the\n            output Tensor. The result tensor will have fewer dimension\n            than the :attr:`input` unless :attr:`keepdim` is true, default\n            value is False.\n        name (str, optional): The default value is None. Normally there is no need for\n            user to set this property. For more information, please refer to :ref:`api_guide_Name`.\n\n    Returns:\n        Tensor: results of norm operation on the specified axis of input tensor,\n        it's data type is the same as input's Tensor.\n\n    Examples:\n        .. code-block:: python\n\n            import paddle\n            import numpy as np\n            shape=[2, 3, 4]\n            np_input = np.arange(24).astype('float32') - 12\n            np_input = np_input.reshape(shape)\n            x = paddle.to_tensor(np_input)\n            #[[[-12. -11. -10.  -9.] [ -8.  -7.  -6.  -5.] [ -4.  -3.  -2.  -1.]]\n            # [[  0.   1.   2.   3.] [  4.   5.   6.   7.] [  8.   9.  10.  11.]]]\n\n            # compute frobenius norm along last two dimensions.\n            out_fro = paddle.linalg.norm(x, p='fro', axis=[0,1])\n            # out_fro.numpy() [17.435596 16.911535 16.7332   16.911535]\n\n            # compute 2-order vector norm along last dimension.\n            out_pnorm = paddle.linalg.norm(x, p=2, axis=-1)\n            #out_pnorm.numpy(): [[21.118711  13.190906   5.477226]\n            #                    [ 3.7416575 11.224972  19.131126]]\n\n            # compute 2-order  norm along [0,1] dimension.\n            out_pnorm = paddle.linalg.norm(x, p=2, axis=[0,1])\n            #out_pnorm.numpy(): [17.435596 16.911535 16.7332   16.911535]\n\n            # compute inf-order  norm\n            out_pnorm = paddle.linalg.norm(x, p=np.inf)\n            #out_pnorm.numpy()  = [12.]\n            out_pnorm = paddle.linalg.norm(x, p=np.inf, axis=0)\n            #out_pnorm.numpy(): [[12. 11. 10. 9.] [8. 7. 6. 7.] [8. 9. 10. 11.]]\n\n            # compute -inf-order  norm\n            out_pnorm = paddle.linalg.norm(x, p=-np.inf)\n            #out_pnorm.numpy(): [0.]\n            out_pnorm = paddle.linalg.norm(x, p=-np.inf, axis=0)\n            #out_pnorm.numpy(): [[0. 1. 2. 3.] [4. 5. 6. 5.] [4. 3. 2. 1.]]\n    "

    def frobenius_norm(input, dim=None, keepdim=False, name=None):
        '\n        The frobenius norm OP is to calculate the frobenius norm of certain two dimensions of Tensor `input`.\n        Args:\n          input (Variable): Tensor, data type float32, float64.\n          dim (list, optional): None for last two dimensions.\n          keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.\n        '
        if ((dim is not None) and (not (isinstance(dim, list) and (len(dim) == 2)))):
            raise ValueError('The dim of frobenius norm op should be None or two elements list!')
        if paddle.in_dynamic_mode():
            if (dim is None):
                return _C_ops.frobenius_norm(input, 'keep_dim', keepdim, 'reduce_all', True)
            return _C_ops.frobenius_norm(input, 'dim', dim, 'keep_dim', keepdim, 'reduce_all', False)
        attrs = {'dim': dim, 'keep_dim': keepdim, 'reduce_all': False}
        if (dim is None):
            attrs['reduce_all'] = True
        check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'frobenius_norm')
        helper = LayerHelper('frobenius_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='frobenius_norm', inputs={'X': input}, outputs={'Out': out}, attrs=attrs)
        return out

    def vector_norm(input, porder=None, axis=None, keepdim=False, asvector=False, name=None):
        '\n        Calculate the p-order vector norm for certain  dimension of Tensor `input`.\n        Args:\n          input (Variable): Tensor, data type float32, float64.\n          porder (float, optional): None for porder=2.0.\n          axis (int, optional): None for last dimension.\n          keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.\n        '
        if paddle.in_dynamic_mode():
            if (axis is None):
                axis = (- 1)
            return _C_ops.p_norm(input, 'porder', porder, 'axis', axis, 'keepdim', keepdim, 'asvector', asvector)
        if (porder is not None):
            check_type(porder, 'porder', (float, int), 'p_norm')
        if (axis is not None):
            check_type(axis, 'axis', int, 'p_norm')
        check_variable_and_dtype(input, 'input', ['float32', 'float64'], 'p_norm')
        attrs = {'axis': (axis if (axis is not None) else (- 1)), 'porder': (float(porder) if (porder is not None) else 2.0), 'keepdim': keepdim, 'asvector': asvector, 'epsilon': 1e-12}
        helper = LayerHelper('p_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='p_norm', inputs={'X': input}, outputs={'Out': out}, attrs=attrs)
        return out

    def inf_norm(input, porder=None, axis=axis, keepdim=False, asvector=False, name=None):
        helper = LayerHelper('frobenius_norm', **locals())
        out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        helper.append_op(type='abs', inputs={'X': input}, outputs={'Out': out})
        reduce_out = helper.create_variable_for_type_inference(dtype=helper.input_dtype())
        reduce_all = (True if ((axis == None) or (axis == []) or (asvector == True)) else False)
        axis = (axis if ((axis != None) and (axis != [])) else [0])
        reduce_type = ('reduce_max' if (porder == np.float('inf')) else 'reduce_min')
        helper.append_op(type=reduce_type, inputs={'X': out}, outputs={'Out': reduce_out}, attrs={'dim': axis, 'keep_dim': keepdim, 'reduce_all': reduce_all})
        return reduce_out

    def p_matrix_norm(input, porder=1.0, axis=axis, keepdim=False, name=None):
        '\n        NOTE:\n            This function actually treats the matrix as flattened vector to calculate vector norm instead of matrix norm.\n        '
        block = LayerHelper('norm', **locals())
        out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        abs_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='abs', inputs={'X': input}, outputs={'Out': abs_out})
        pow_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='pow', inputs={'X': abs_out}, outputs={'Out': pow_out}, attrs={'factor': porder})
        sum_out = block.create_variable_for_type_inference(dtype=block.input_dtype())
        block.append_op(type='reduce_sum', inputs={'X': pow_out}, outputs={'Out': sum_out}, attrs={'dim': axis, 'keep_dim': keepdim, 'reduce_all': (True if (axis is None) else False)})
        porder
        block.append_op(type='pow', inputs={'X': sum_out}, outputs={'Out': out}, attrs={'factor': float((1.0 / porder))})
        return out
    if ((axis is None) and (p is not None)):
        if isinstance(p, str):
            if (p == 'fro'):
                return frobenius_norm(x, dim=axis, keepdim=keepdim, name=name)
            else:
                raise ValueError("only valid string values are 'fro', found {}".format(p))
        elif isinstance(p, (int, float)):
            return vector_norm(x, porder=p, axis=axis, keepdim=keepdim, asvector=True, name=name)
        else:
            raise ValueError('only valid p type is string or float, found {}'.format(type(p)))
    if isinstance(axis, tuple):
        axis = list(axis)
    if (isinstance(axis, list) and (len(axis) == 1)):
        axis = axis[0]
    if isinstance(axis, int):
        if isinstance(p, str):
            if (p == 'fro'):
                return vector_norm(x, porder=2, axis=axis, keepdim=keepdim, asvector=False, name=name)
            else:
                raise ValueError("only valid string values are 'fro', found {}".format(p))
        elif isinstance(p, (int, float)):
            return vector_norm(x, axis=axis, porder=p, keepdim=keepdim, asvector=False, name=name)
        else:
            raise ValueError('unspport p for p-order vector norm. except float, found {}'.format(p))
    elif (isinstance(axis, list) and (len(axis) == 2)):
        if (p == 'fro'):
            return frobenius_norm(x, dim=axis, keepdim=keepdim, name=name)
        elif ((p == np.inf) or (p == (- np.inf))):
            return inf_norm(x, porder=p, axis=axis, keepdim=keepdim, name=name)
        elif (p == 0):
            raise ValueError('just suport axis type int or list (length of list <=1) if p = 0, found {}'.format(axis))
        else:
            return p_matrix_norm(x, porder=p, axis=axis, keepdim=keepdim, name=name)
    else:
        raise ValueError('except axis type int or list (length of list <=2), found {}'.format(axis))