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) – Number of quantization levels
vmin (float, optional) – Minimum value for quantization
vmax (float, optional) – Maximum value for quantization
include_vmax (bool) – Whether to include max value in quantization True: Quantize with spacing of 1/levels False: Quantize with spacing of 1/(levels-1)
- 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)