.. _op_ai_onnx_LpNormalization: LpNormalization =============== - **Domain**: ``ai.onnx`` - **Since version**: 22 Given a matrix, apply Lp-normalization along the provided axis. The output is computed as: ``output = input / Lp_norm(input, axis)``. When the Lp norm is zero (i.e., all elements along the axis are zero), the output is defined to be zero to avoid division by zero. **Inputs** - **input** (*T*): Input matrix **Outputs** - **output** (*T*): Matrix after normalization **Attributes** - **axis** (*int*): The axis on which to apply normalization, -1 mean last axis. - **p** (*int*): The order of the normalization, only 1 or 2 are supported. **Type Constraints** - **T**: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16). Examples -------- **test_cc_lpnormalization_axis0_p1** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = 0 p = 1 .. code-block:: text Inputs: x: shape=(2, 2, 3), dtype=float32 [[[1., 2., 2.], [3., 4., 0.]], [[0., 5., 5.], [6., 8., 0.]]] Outputs: y: shape=(2, 2, 3), dtype=float32 [[[1. , 0.2857143 , 0.2857143 ], [0.33333334, 0.33333334, 0. ]], [[0. , 0.71428573, 0.71428573], [0.6666667 , 0.6666667 , 0. ]]] **test_cc_lpnormalization_default** .. code-block:: text Node: LpNormalization(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 2, 3), dtype=float32 [[[1., 2., 2.], [3., 4., 0.]], [[0., 5., 5.], [6., 8., 0.]]] Outputs: y: shape=(2, 2, 3), dtype=float32 [[[0.33333334, 0.6666667 , 0.6666667 ], [0.6 , 0.8 , 0. ]], [[0. , 0.70710677, 0.70710677], [0.6 , 0.8 , 0. ]]] **test_l1normalization_axis_0** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = 0 p = 1 .. code-block:: text Inputs: x: shape=(2,), dtype=float32 [3., 4.] Outputs: y: shape=(2,), dtype=float32 [0.42857143, 0.5714286 ] **test_l1normalization_axis_1** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = 1 p = 1 .. code-block:: text Inputs: x: shape=(2, 2), dtype=float32 [[3., 4.], [6., 8.]] Outputs: y: shape=(2, 2), dtype=float32 [[0.42857143, 0.5714286 ], [0.42857143, 0.5714286 ]] **test_l1normalization_axis_last** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = -1 p = 1 .. code-block:: text Inputs: x: shape=(2, 2, 3), dtype=float32 [[[1., 2., 2.], [3., 4., 0.]], [[0., 5., 5.], [6., 8., 0.]]] Outputs: y: shape=(2, 2, 3), dtype=float32 [[[0.2 , 0.4 , 0.4 ], [0.42857143, 0.5714286 , 0. ]], [[0. , 0.5 , 0.5 ], [0.42857143, 0.5714286 , 0. ]]] **test_l2normalization_axis_0** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = 0 p = 2 .. code-block:: text Inputs: x: shape=(2, 2, 3), dtype=float32 [[[1., 2., 2.], [3., 4., 0.]], [[0., 5., 5.], [6., 8., 0.]]] Outputs: y: shape=(2, 2, 3), dtype=float32 [[[1. , 0.37139067, 0.37139067], [0.4472136 , 0.4472136 , 0. ]], [[0. , 0.9284767 , 0.9284767 ], [0.8944272 , 0.8944272 , 0. ]]] **test_l2normalization_axis_1** .. code-block:: text Node: LpNormalization(x) -> (y) Attributes: axis = 1 p = 2 .. code-block:: text Inputs: x: shape=(2, 2), dtype=float32 [[3., 4.], [6., 8.]] Outputs: y: shape=(2, 2), dtype=float32 [[0.6, 0.8], [0.6, 0.8]] Differences with previous version (1) ------------------------------------- **SchemaDiff**: ``LpNormalization`` (domain ``'ai.onnx'``) * old version: 1 * new version: 22 * breaking: no **Type constraints:** * changed 'T': added types: ['tensor(bfloat16)'] Version History --------------- - :doc:`Version 1 `