1、二維tensor
x = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.reduce_max(x) # 6
tf.reduce_max(x, 0) # [4, 5, 6]
tf.reduce_max(x, 1) # [3, 6]
tf.reduce_max(x, 1, keepdims=True) # [[3], [6]]
tf.reduce_max(x, [0, 1]) # 6
2、三維tensor
x = tf.reshape(np.arange(24), [4, 3, 2]) #(4,3,2)
[[[ 0 1]
[ 2 3]
[ 4 5]]
[[ 6 7]
[ 8 9]
[10 11]]
[[12 13]
[14 15]
[16 17]]
[[18 19]
[20 21]
[22 23]]]
(1)
tf.reduce_max(x) #23
tf.reduce_max(x, axis=[0,1,2]) #23
(2)
tf.reduce_max(x, axis=[0]) #(3,2)
#[[18 19]
# [20 21]
# [22 23]]
tf.reduce_max(x, axis=[1]) #(4,2)
tf.reduce_max(x, axis=[2]) #(4,3)
(3)
tf.reduce_max(x, axis=[0,1]) #(2,)
# [22 23]
tf.reduce_max(x, axis=[0,2]) #(3,)
tf.reduce_max(x, axis=[1,2]) #(4,)