Bins the given values for use in a histogram.
View aliases
Compat aliases for migration
See Migration guide for more details.
tf.histogram_fixed_width_bins(
values,
value_range,
nbins=100,
dtype=tf.dtypes.int32
,
name=None
)
Given the tensor values
, this operation returns a rank 1 Tensor
representing the indices of a histogram into which each element
of values
would be binned. The bins are equal width and
determined by the arguments value_range
and nbins
.
Returns | |
---|---|
A Tensor holding the indices of the binned values whose shape matches
values .
|
Raises | |
---|---|
TypeError
|
If any unsupported dtype is provided. |
tf.errors.InvalidArgumentError
|
If value_range does not satisfy value_range[0] < value_range[1]. |
Examples:
# Bins will be: (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)
nbins = 5
value_range = [0.0, 5.0]
new_values = [-1.0, 0.0, 1.5, 2.0, 5.0, 15]
indices = tf.histogram_fixed_width_bins(new_values, value_range, nbins=5)
indices.numpy()
array([0, 0, 1, 2, 4, 4], dtype=int32)