# tensorplay.functional.quantize_per_tensor Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.quantize_per_tensor.html ```python tensorplay.functional.quantize_per_tensor(input, scale, zero_point, dtype) → Tensor ``` Converts a float tensor to a quantized tensor with given scale and zero point. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – float tensor or list of tensors to quantize - scale ([float](https://docs.python.org/3/builtins/functions.html#float) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – scale to apply in quantization formula - zero_point ([int](https://docs.python.org/3/builtins/functions.html#int) or [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – offset in integer value that maps to float zero - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType)) – the desired data type of returned tensor. Has to be one of the quantized dtypes: tensorplay.quint8, tensorplay.qint8, tensorplay.qint32 Returns: A newly quantized tensor or list of quantized tensors. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8).int_repr() tensor([ 0, 10, 20, 30], dtype=tensorplay.uint8) >>> tensorplay.quantize_per_tensor([tensorplay.tensor([-1.0, 0.0]), tensorplay.tensor([-2.0, 2.0])], >>> tensorplay.tensor([0.1, 0.2]), tensorplay.tensor([10, 20]), tensorplay.quint8) (tensor([-1., 0.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10), tensor([-2., 2.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.2, zero_point=20)) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), tensorplay.tensor(0.1), tensorplay.tensor(10), tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.10, zero_point=10) ```