normalize

function of dascore.proc.basic source

normalize(
    self: Patch ,
    dim: str ,
    norm: Literal[‘l1’, ‘l2’, ‘max’, ‘bit’] = l2,
)-> ‘PatchType’

Normalize a patch along a specified dimension.

NaN values are ignored when computing the norm. They remain NaN in the output but do not affect any other sample. Slices with a norm of zero, meaning they contain nothing but zeros and NaN, are returned unscaled.

Parameters

Parameter Description
dim The dimension along which the normalization takes place.
norm Determines the value to divide each sample by along a given axis.
Options are:
l1 - divide each sample by the l1 of the axis.
l2 - divide each sample by the l2 of the axis.
max - divide each sample by the maximum of the absolute value of the axis.
bit - sample-by-sample normalization (-1/+1)

Examples

import dascore as dc
patch = dc.get_example_patch()

# L2 normalization along time dimension
l2_norm = patch.normalize(dim="time", norm="l2")

# Max normalization along distance dimension
max_norm = patch.normalize(dim="distance", norm="max")

# Bit normalization (sign only)
bit_norm = patch.normalize(dim="time", norm="bit")