【发布时间】:2022-01-21 19:27:51
【问题描述】:
我想获取 3 维张量的出现次数(显示在相应索引处的张量中,就像 tf.math.bincount 一样)。
对于二维张量,您可以这样做:
T = tf.round(25*tf.random.uniform((5,8)))
bincounts = tf.cast(tf.math.bincount(T, axis=-1),tf.float32)
但在 3d 张量上,我发现的唯一方法是在第三维上循环,如下所示:
third_dim = 10
T = tf.round(25*tf.random.uniform((5,8,third_dim)))
bincounts = []
for i in range(third_dim):
bincounts.append(tf.math.bincount(T[:,:,i], axis=-1))
bincounts = tf.stack(bincounts,-1)
有谁知道是否有办法直接在所有维度上应用这样的函数?
【问题讨论】:
标签: python tensorflow counting rank find-occurrences