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
) – The Lp norm to use for normalization. Default is L2 norm (p=2). (default:2
)axis (
Optional
[int
]) – Axis along which to normalize. IfNone
, the whole array is normalized. (default:None
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – The normalized array.
Examples
>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> ivy.lp_normalize(x, p=1, axis=1) ivy.array([[0.3333, 0.6666], [0.75, 1.]])
- Array.lp_normalize(self, /, *, p=2, axis=None, out=None)#
Normalize the array to have Lp norm.
- Parameters:
self (
Array
) – Input array.p (
float
) – p-norm to use for normalization. (default:2
)axis (
Optional
[int
]) – Axis along which to normalize. IfNone
, the whole array (default:None
) is normalized.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a (default:None
) shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – The normalized array.
Examples
>>> x = ivy.array([[1., 2.], [3., 4.]]) >>> x.lp_normalize(p=2, axis=1) ivy.array([[0.4472, 0.8944], [0.6, 0.8]])
- Container.lp_normalize(self, p=2, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
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 – The input container with leaves to be normalized.
axis (
Optional
[int
]) – The axis along which to normalize. (default:None
)key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) 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.static_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]]) }