📜  Python – histogram_fixed_width_bins()

📅  最后修改于: 2022-05-13 01:54:28.181000             🧑  作者: Mango

Python – histogram_fixed_width_bins()

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

histogram_fixed_width_bins()用于查找元素将被分箱的索引。

示例 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())


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


输出:

res:  [3 0 1 2 5 5]

示例 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())

输出:

res:  [4 0 2 3 5 1]