data = tf.constant( [ [ [0, 2, 4, 1], [1, 0, 0, 2] ], [ [1, 0, 4, 6], [2, 6, 3, 1] ] ] )
indices = tf.argmax(data, axis=2)
如何在张量流中获得结果[ [4 2], [6 6] ]
?
请帮助我!!!
答案 0 :(得分:0)
根据情况使用tf.reduce_max()
data = tf.constant([[ [0, 2, 4, 1],[1, 0, 0, 2]], [ [1, 0, 4, 6], [2, 6, 3, 1] ]])
maximum_values = tf.reduce_max(data, reduction_indices=[2])
with tf.Session() as sess:
p=sess.run(maximum_values)
print(p)
[[4 2]
[6 6]]
编辑:要访问其他值,可以按索引进行切片,然后使用tf.concat
或tf.stack
。例如,如果您想获得[[0 2] [3 1]]
,可以尝试
with tf.Session() as sess:
p=sess.run(data[0][0][0:2])
print(p)
[0 2]
q=sess.run(data[1][1][2:])
print(q)
[3 1]
r=sess.run(tf.stack([p,q],0))
print(r)
[[0 2]
[3 1]]