Python ``tensorflow.histogram_fixed_width()`` 函数用法与代码示例


发布日期 : 2021-02-26 13:25:33 UTC

访问量: 10 次浏览

Python – tensorflow.histogram\_fixed\_width()

TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

histogram\_fixed\_width()用于寻找直方图的值。

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

参数:

  • values: 它是一个数字张量。
  • value\_range: 它是一个形状[2]的张量,其 dtypevalue 相同。
  • nbins(可选): 它定义了直方图中的bin的数量。默认值是100。
  • dtype(可选): 它定义了返回直方图的d类型。默认值是int32。
  • name(可选): 它定义了操作的名称。

返回:
它返回一个直方图值的张量。

示例 1:

# 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())

输出:

res: [1 1 1 1 0 2]

示例 2:

# 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]