TensorFlow histogram_fixed_width_bins () 使用方法


发布日期 : 2022-05-14 05:12:35 UTC

访问量: 10 次浏览

Python – histogram\_fixed\_width\_bins()

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

histogram\_fixed\_width\_bins()是用来找到元素被分档的索引的。

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

参数:

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

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

示例 1:

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

输出:

res: [3 0 1 2 5 5]

示例 2:

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

输出:

res: [4 0 2 3 5 1]