def quantize_by_scale_and_zp(
    input_data: np.ndarray,
    scale: np.ndarray,
    zero_point: Optional[np.ndarray],
    output_dtype: Union["types", str],
) -> np.ndarray:
    """Given scale and zero_point (if any), calculate quantized data."""
    if isinstance(output_dtype, str):
        output_dtype = types.string_to_builtin(output_dtype)
    output_range = types.type_mapping.builtin_to_range(output_dtype)

    if _need_manual_broadcast(scale, input_data):
        scale = repeat_data_as(scale, input_data.shape)
    quantized_data = input_data / scale
    if types.is_int(output_dtype):
        quantized_data = np.around(quantized_data)
    if zero_point is not None:
        if _need_manual_broadcast(zero_point, input_data):
            zero_point = repeat_data_as(zero_point, input_data.shape)
        quantized_data += zero_point.astype(np.float32)
    quantized_data = np.clip(quantized_data, output_range.low, output_range.high)
    return _cast_to_quantized_dtype(quantized_data, output_dtype)
Given scale and zero_point (if any), calculate quantized data.
coremltools/optimize/_utils.py