pado.optical_element.quantize¶
- quantize(x, levels, vmin=None, vmax=None, include_vmax=True)[source]¶
Quantize floating point array.
Discretize input array into specified number of levels.
- Parameters:
x (torch.Tensor or np.ndarray) – Input array to quantize
levels (int) – Nonnegative number of levels; zero disables quantization. One level returns the lower bound. A constant input remains finite.
vmin (float, optional) – Lower bound when include_vmax=False.
vmax (float, optional) – Upper bound when include_vmax=False.
include_vmax (bool) – Historical bin convention. True uses the observed input range with spacing (max-min)/levels and excludes its maximum; False uses spacing (vmax-vmin)/(levels-1), including both bounds.
- Returns:
Quantized array
- Return type:
torch.Tensor or np.ndarray
Examples
>>> x = torch.randn(100) >>> x_quant = quantize(x, levels=8) >>> x_quant = quantize(x, levels=16, vmin=-1, vmax=1, include_vmax=False)