在我看来,numpy 函数bincount
非常有用且易于使用,所以我很自然地使用了 TensorFlow 中的模拟函数。最近我了解到不幸tf.bincount
的是没有 GPU 支持(你可以在这里阅读)。有没有其他方法可以在带有GPU 的 TensorFlow 中高效地进行加权直方图,如下例所示?
sess = tf.Session()
values = tf.random_uniform((1,50),10,20,dtype = tf.int32)
weights = tf.random_uniform((1,50),0,1,dtype = tf.float32)
counts = tf.bincount(values, weights = weights)
histogram = sess.run(counts)
print(histogram)