lp_norm¶

dragon.nn.lp_norm(
inputs,
axis=- 1,
end_axis=None,
p=2,
epsilon=1e-12,
reduction='sum',
**kwargs
)[source]

Apply the lp normalization.

The normalization is defined as:

$y = \frac{x}{\max(\left\|x\right\|_{p}, \epsilon)}$

axis could be negative:

x = dragon.constant([[1, 2, 3], [4, 5, 6]], 'float32')
# A negative axis is the last-k axis
print(dragon.nn.lp_norm(x, 1))
print(dragon.nn.lp_norm(x, -1))  # Equivalent

More than one axis could be specified to reduce:

# Along the continuous axes: [axis, end_axis]
print(dragon.nn.lp_norm(x, axis=0, end_axis=1))
Parameters:
• inputs (dragon.Tensor) – The tensor $$x$$.
• p (int, optional, default=2) – The order of the normalization.
• axis (int, optional, default=-1) – The first axis to reduce.
• end_axis (int, optional) – The last axis to reduce.
• epsilon (float, optional, default=1e-12) – The value to $$\epsilon$$.
• reduction ({'sum', 'mean'}, optional) – The reduction method for norm.
Returns:

dragon.Tensor – The output tensor.