(arr, num_buckets)
return arr
Quantizes a numpy array.

  This function maps each scalar in arr to the center of one of num_buckets
  buckets. For instance,
  quantize_array([0, 0.3, 0.6, 1], 2) => [0.25, 0.25, 0.75, 0.75]

  Args:
    arr: The numpy array to quantize.
    num_buckets: The number of buckets to map "var" to.
  Returns:
    The quantized numpy array.
  Raises:
    ValueError: when num_buckets < 1.
Quantizes a numpy array.
Quantizes a numpy array .
def quantize_array(arr, num_buckets):
  """Quantizes a numpy array.

  This function maps each scalar in arr to the center of one of num_buckets
  buckets. For instance,
  quantize_array([0, 0.3, 0.6, 1], 2) => [0.25, 0.25, 0.75, 0.75]

  Args:
    arr: The numpy array to quantize.
    num_buckets: The number of buckets to map "var" to.
  Returns:
    The quantized numpy array.
  Raises:
    ValueError: when num_buckets < 1.
  """
  if num_buckets < 1:
    raise ValueError("num_buckets must be >= 1")
  arr_max = arr.max()
  arr_min = arr.min()
  if arr_max == arr_min:
    return arr
  bucket_width = (arr_max - arr_min) / num_buckets
  # Map scalars to bucket indices. Take special care of max(arr).
  bucket_indices = np.floor((arr - arr_min) / bucket_width)
  bucket_indices[bucket_indices == num_buckets] = num_buckets - 1
  # Map each scalar to the center of a bucket.
  arr = arr_min + bucket_width * (bucket_indices + 0.5)
  return arr
def quantize_array ( arr , num_buckets ) : if num_buckets < 1 : raise ValueError ( "num_buckets must be >= 1" ) arr_max = arr . max ( ) arr_min = arr . min ( ) if arr_max == arr_min : return arr bucket_width = ( arr_max - arr_min ) / num_buckets # Map scalars to bucket indices. Take special care of max(arr). bucket_indices = np . floor ( ( arr - arr_min ) / bucket_width ) bucket_indices [ bucket_indices == num_buckets ] = num_buckets - 1 # Map each scalar to the center of a bucket. arr = arr_min + bucket_width * ( bucket_indices + 0.5 ) return arr