Table Of Contents
Table Of Contents


mxnet.ndarray.contrib.quantize(data=None, min_range=None, max_range=None, out_type=_Null, out=None, name=None, **kwargs)

Quantize a input tensor from float to out_type, with user-specified min_range and max_range.

min_range and max_range are scalar floats that specify the range for the input data.

When out_type is uint8, the output is calculated using the following equation:

out[i] = (in[i] - min_range) * range(OUTPUT_TYPE) / (max_range - min_range) + 0.5,

where range(T) = numeric_limits<T>::max() - numeric_limits<T>::min().

When out_type is int8, the output is calculate using the following equation by keep zero centered for the quantized value:

out[i] = sign(in[i]) * min(abs(in[i] * scale + 0.5f, quantized_range),

where quantized_range = MinAbs(max(int8), min(int8)) and scale = quantized_range / MaxAbs(min_range, max_range).


This operator only supports forward propogation. DO NOT use it in training.

Defined in src/operator/quantization/

  • data (NDArray) – A ndarray/symbol of type float32

  • min_range (NDArray) – The minimum scalar value possibly produced for the input

  • max_range (NDArray) – The maximum scalar value possibly produced for the input

  • out_type ({'int8', 'uint8'},optional, default='uint8') – Output data type.

  • out (NDArray, optional) – The output NDArray to hold the result.


out – The output of this function.

Return type

NDArray or list of NDArrays