tf.reduce_max

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,)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章