def create_weight_with_inf(weight, inf_ratio, inf_val=np.inf):
    """Create weight that has the same shape as input weight, but with inf_ratio elements set as inf_val."""
    shape = list(weight.shape)
    size = np.prod(shape)
    weight = 100 * np.random.rand(size)
    num_of_inf = int(size * inf_ratio)
    weight[:num_of_inf] = inf_val
    np.random.shuffle(weight)
    return np.reshape(weight, shape).astype(np.float32)
Create weight that has the same shape as input weight, but with inf_ratio elements set as inf_val.
coremltools/test/optimize/coreml/test_post_training_quantization.py