tf.keras.ops.histogram

Computes a histogram of the data tensor x.

x Input tensor.
bins An integer representing the number of histogram bins. Defaults to 10.
range A tuple representing the lower and upper range of the bins. If not specified, it will use the min and max of x.

A tuple containing:

  • A tensor representing the counts of elements in each bin.
  • A tensor representing the bin edges.

Example:

input_tensor = np.random.rand(8)
keras.ops.histogram(input_tensor)
(array([1, 1, 1, 0, 0, 1, 2, 1, 0, 1], dtype=int32),
array([0.0189519 , 0.10294958, 0.18694726, 0.27094494, 0.35494262,
    0.43894029, 0.52293797, 0.60693565, 0.69093333, 0.77493101,
    0.85892869]))