lp_normalize#
- ivy.lp_normalize(x, /, *, p=2, axis=None, out=None)[source]#
Normalize the input array along the given axis to have Lp norm equal to 1.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array.p (
float
, default:2
) – The Lp norm to use for normalization. Default is L2 norm (p=2).axis (
Optional
[int
], default:None
) – Axis along which to normalize. IfNone
, the whole array is normalized.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – The normalized array.
Examples
>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> y = ivy.lp_normalize(x, p=1, axis=1) >>> print(y) ivy.array([[0.33333334, 0.66666669], [0.42857143, 0.5714286 ]])
- Array.lp_normalize(self, /, *, p=2, axis=None, out=None)[source]#
Normalize the array to have Lp norm.
- Parameters:
self (
Array
) – Input array.p (
float
, default:2
) – p-norm to use for normalization.axis (
Optional
[int
], default:None
) – Axis along which to normalize. IfNone
, the whole array is normalized.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – The normalized array.
Examples
>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> y = x.lp_normalize(p=2, axis=1) >>> print(y) ivy.array([[0.44721359, 0.89442718], [0.60000002, 0.80000001]])
- Container.lp_normalize(self, p=2, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.l2_normalize. This method simply wraps the function, and so the docstring for ivy.l2_normalize also applies to this method with minimal changes.
- Parameters:
self (
Container
) – The input container with leaves to be normalized.axis (
Optional
[Union
[int
,Container
]], default:None
) – The axis along which to normalize.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the normalized leaves.
Examples
>>> x = ivy.Container(a=ivy.array([[0.5, 1.5, 2.5], [3.5, 4.5, 5.5]]), ... b=ivy.array([[-1., -1.], [-1., -0.5]])) >>> y = x.lp_normalize(axis=1) >>> print(y) { a: ivy.array([[0.16903085, 0.50709254, 0.84515423], [0.44183609, 0.56807494, 0.69431382]]), b: ivy.array([[-0.70710677, -0.70710677], [-0.89442718, -0.44721359]]) }