Python – tensorflow.histogram_fixed_width()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

histogram_fixed_width() is used to find the histogram values.

Syntax: tensorflow.histogram_fixed_width( values, value_range, nbins, dtype, name )

Parameters:

  • values: It is a numeric Tensor.
  • value_range: It is a Tensor of shape [2] with same dtype as values.
  • nbins(optional): It defines the number of bins in histogram. Default value is 100.
  • dtype(optional): It defines the dtype of returned histogram. Default value is int32.
  • name(optional): It defines the name of the operation.  

Returns: It returns a Tensor of histogram values.



Example 1:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Initializing the input
nbins = 6
value_range = [0.0, 6.0]
new_values = [3.0, 0.0, 1.5, 2.0, 5.0, 15]
  
# Finding histogram values
hist = tf.histogram_fixed_width(new_values, value_range, nbins)
  
# Printing the result
print("res: ", hist.numpy())

chevron_right


Output:


res:  [1 1 1 1 0 2]

Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Initializing the input
nbins = 6
value_range = [0.0, 4.0]
new_values = [3.0, 0.0, 1.5, 2.0, 5.0, 1.0]
  
# Finding histogram values
hist = tf.histogram_fixed_width(new_values, value_range, nbins)
  
# Printing the result
print("res: ", hist.numpy())

chevron_right


Output:


res:  [1 1 1 1 1 1]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.