答案 0 :(得分:1)
我想你想要tf.reduce_min。要找到[10, 3, 5, 4]
的最小值:
import tensorflow as tf
def one_dim_graph():
input_tensor = tf.constant([10, 3, 5, 4])
tensor_min = tf.reduce_min(input_tensor)
return input_tensor, tensor_min
def run():
in_one, g_one = one_dim_graph()
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
out_one = sess.run([g_one])
print in_one
print out_one
run()
这会给你min:
Tensor("Const_74:0", shape=(4,), dtype=int32)
[3]
您还可以在多维张量中使用此功能,并缩小所有尺寸或沿某个尺寸缩小。因此,例如,找到min:
[[1, 4, 3, 10],
[6, 5, 2, 12],
[9, 7, 8, 11]]
我们可以找到:
[1]
与tf.reduce_min(input_tensor)
[1, 4, 2, 10]
tf.reduce_min(input_tensor, reduction_indices=0)
[1, 2, 7]
tf.reduce_min(input_tensor, reduction_indices=1)