tf.histogram_fixed_width

View source on GitHub

Return histogram of values.

tf.histogram_fixed_width(
    values, value_range, nbins=100, dtype=tf.dtypes.int32, name=None
)

Given the tensor values, this operation returns a rank 1 histogram counting the number of entries in values that fell into every bin. The bins are equal width and determined by the arguments value_range and nbins.

Args:

Returns:

A 1-D Tensor holding histogram of values.

Raises:

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]

with tf.compat.v1.get_default_session() as sess:
  hist = tf.histogram_fixed_width(new_values, value_range, nbins=5)
  variables.global_variables_initializer().run()
  sess.run(hist) => [2, 1, 1, 0, 2]