HomeLanguagesPython – histogram_fixed_width_bins()

Python – histogram_fixed_width_bins()

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

histogram_fixed_width_bins() is used to find the indices into which elements would be binned.

Syntax: tensorflow.histogram_fixed_width_bins( 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 indices. Default value is int32.
  • name(optional): It defines the name of the operation.  

Returns: It returns a Tensor of histogram values.

Example 1:

Python3




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


Output:

res:  [3 0 1 2 5 5]

Example 2:

Python3




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


Output:

res:  [4 0 2 3 5 1]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS