tf.reduce_max()函数的用法详解
生活随笔
收集整理的這篇文章主要介紹了
tf.reduce_max()函数的用法详解
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
tf.reduce_max()函數(shù)
tf.reduce_max(input_tensor,axis=None,name=None,keepdims=False #是否保持矩形原狀 )參數(shù)解釋:
input_tensor:輸入數(shù)據(jù),tensor、array、dataframe 都可以
axis:表示維度,從0開始表示最外層維度,也可以用-1表示最內(nèi)層維度;
????????? [0, [1, [2, [3,[...]]]]],或者[[[[[...], -4], -3], -2], -1]? 數(shù)字表示對(duì)應(yīng)[ ]的維度。當(dāng)axis位默認(rèn)表示求全局最大值。
keepdims:默認(rèn)時(shí),維度會(huì)減少1,為True時(shí),保持維度不變。
name:操作名稱
reduction_indices:axis的舊名稱(已經(jīng)棄用)
示例:
import tensorflow as tf import numpy as npa=np.array([[1, 2],[5, 3],[2, 6]])b = tf.Variable(a) with tf.Session() as sess:sess.run(tf.global_variables_initializer())print(sess.run(b))print('************')# 對(duì)于二維矩陣,axis=0軸可以理解為行增長(zhǎng)方向(向下)即按列求最值,axis=1軸可以理解為列增長(zhǎng)方向(向右)按列行求最值print(sess.run(tf.reduce_max(b, axis=1, keepdims=False))) # keepdims=False,axis=1被消減,不保持原狀,本來shape為(3,1),后來變成(1,3)了print('************')print(sess.run(tf.reduce_max(b, axis=1, keepdims=True)))print('************')print(sess.run(tf.reduce_max(b, axis=0, keepdims=True)))結(jié)果:
[[1 2][5 3][2 6]] ************ [2 5 6] ************ [[2][5][6]] ************ [[5 6]]ps:另外該函數(shù)等價(jià)于np.max:(a, axis=None, out=None, keepdims=False)
import tensorflow as tf import numpy as npmax_value = tf.reduce_max([[1, 3, 2], [4,5,6]], axis=0) with tf.Session() as sess:max_value = sess.run(max_value)print(max_value)print(np.max([[1, 3, 2], [4,5,6]], axis=0))#### 輸出 [4 5 6] [4 5 6]?
總結(jié)
以上是生活随笔為你收集整理的tf.reduce_max()函数的用法详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tf.boolean_mask()的详细
- 下一篇: 目标检测 /yolo算法原理的详解