tft.apply_buckets

Returns a bucketized column, with a bucket index assigned to each input.

Each element e in x is mapped to a positive index i for which bucket_boundaries[i-1] <= e < bucket_boundaries[i], if it exists. If e < bucket_boundaries[0], then e is mapped to 0. If e >= bucket_boundaries[-1], then e is mapped to len(bucket_boundaries). NaNs are mapped to len(bucket_boundaries).

Example:

x = tf.constant([[4.0, float('nan'), 1.0], [float('-inf'), 7.5, 10.0]])
bucket_boundaries = tf.constant([[2.0, 5.0, 10.0]])
tft.apply_buckets(x, bucket_boundaries)
<tf.Tensor: shape=(2, 3), dtype=int64, numpy=
array([[1, 3, 0],
       [0, 2, 3]])>

x A numeric input Tensor, SparseTensor, or RaggedTensor whose values should be mapped to buckets. For CompositeTensors, the non-missing values will be mapped to buckets and missing value left missing.
bucket_boundaries A rank 2 Tensor or list representing the bucket boundaries sorted in ascending order.
name (Optional) A name for this operation.

A Tensor, SparseTensor, or RaggedTensor of the same shape as x, with each element in the returned tensor representing the bucketized value. Bucketized value is in the range [0, len(bucket_boundaries)].