Python – tensorflow.histogram_fixed_width()
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
histogram_fixed_width()用于查找直方图值。
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.
示例 1:
Python3
# 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())
Python3
# 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())
输出:
res: [1 1 1 1 0 2]
示例 2:
Python3
# 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())
输出:
res: [1 1 1 1 1 1]