Home

normalizeL

normalizeL is a function found in several numerical and machine learning libraries that scales a real-valued vector to have unit length under a specified Lp norm. The designation “L” refers to the Lp norm parameter, commonly with a default p = 2, corresponding to the Euclidean norm. In practice, normalizeL computes a normalized vector v_hat = v / ||v||_p, where ||v||_p = (sum_i |v_i|^p)^{1/p} for p >= 1, and ||v||_∞ = max_i |v_i| for p = ∞.

The operation requires handling of edge cases. If the input vector is the zero vector, the norm

Typical uses of normalizeL include preprocessing for machine learning, where features are scaled to a common

Time complexity for normalizeL is linear in the vector size, O(n), with constant extra space, assuming a

is
zero
and
normalization
is
undefined;
implementations
typically
return
the
original
vector,
a
zero
vector,
or
raise
a
warning.
To
improve
numerical
stability,
a
small
epsilon
can
be
added
to
the
denominator.
Different
libraries
may
offer
options
for
behavior
when
the
norm
is
near
zero
or
for
nonstandard
p
values
(e.g.,
p
<
1),
though
p
<
1
yields
a
quasi-norm
that
does
not
satisfy
the
triangle
inequality.
length,
or
in
optimization
and
computer
graphics
where
direction
vectors
are
required
without
altering
magnitude.
It
is
also
used
in
projections
and
similarity
measures
where
the
direction
rather
than
the
magnitude
is
important.
Variants
such
as
normalizeL2,
normalizeL1,
and
normalizeLinf
correspond
to
p
=
2,
p
=
1,
and
p
=
∞,
respectively,
and
some
libraries
expose
normalizeL
with
a
parameter
to
select
among
these
norms.
single
pass
to
compute
the
norm
and
a
second
pass
to
scale.