tf.histogram_fixed_width_bins
Stay organized with collections
Save and categorize content based on your preferences.
Bins the given values for use in a histogram.
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
.
Args |
values
|
Numeric Tensor .
|
value_range
|
Shape [2] Tensor of same dtype as values .
values <= value_range[0] will be mapped to hist[0],
values >= value_range[1] will be mapped to hist[-1].
|
nbins
|
Scalar int32 Tensor . Number of histogram bins.
|
dtype
|
dtype for returned histogram.
|
name
|
A name for this operation (defaults to 'histogram_fixed_width').
|
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.histogram_fixed_width_bins\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/histogram_ops.py#L31-L100) |\n\nBins the given values for use in a histogram.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.histogram_fixed_width_bins`](https://www.tensorflow.org/api_docs/python/tf/histogram_fixed_width_bins)\n\n\u003cbr /\u003e\n\n tf.histogram_fixed_width_bins(\n values,\n value_range,\n nbins=100,\n dtype=../tf/dtypes#int32,\n name=None\n )\n\nGiven the tensor `values`, this operation returns a rank 1 `Tensor`\nrepresenting the indices of a histogram into which each element\nof `values` would be binned. The bins are equal width and\ndetermined by the arguments `value_range` and `nbins`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `values` | Numeric `Tensor`. |\n| `value_range` | Shape \\[2\\] `Tensor` of same `dtype` as `values`. values \\\u003c= value_range\\[0\\] will be mapped to hist\\[0\\], values \\\u003e= value_range\\[1\\] will be mapped to hist\\[-1\\]. |\n| `nbins` | Scalar `int32 Tensor`. Number of histogram bins. |\n| `dtype` | dtype for returned histogram. |\n| `name` | A name for this operation (defaults to 'histogram_fixed_width'). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` holding the indices of the binned values whose shape matches `values`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|\n| `TypeError` | If any unsupported dtype is provided. |\n| [`tf.errors.InvalidArgumentError`](https://www.tensorflow.org/api_docs/python/tf/errors/InvalidArgumentError) | If value_range does not satisfy value_range\\[0\\] \\\u003c value_range\\[1\\]. |\n\n\u003cbr /\u003e\n\n#### Examples:\n\n # Bins will be: (-inf, 1), [1, 2), [2, 3), [3, 4), [4, inf)\n\n nbins = 5\n value_range = [0.0, 5.0]\n new_values = [-1.0, 0.0, 1.5, 2.0, 5.0, 15]\n indices = tf.histogram_fixed_width_bins(new_values, value_range, nbins=5)\n indices.numpy()\n array([0, 0, 1, 2, 4, 4], dtype=int32)"]]