日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

tf.reduce_max()函数的用法详解

發布時間:2024/9/21 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tf.reduce_max()函数的用法详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

tf.reduce_max()函數

tf.reduce_max(input_tensor,axis=None,name=None,keepdims=False #是否保持矩形原狀 )

參數解釋:

input_tensor:輸入數據,tensor、array、dataframe 都可以

axis:表示維度,從0開始表示最外層維度,也可以用-1表示最內層維度;

????????? [0, [1, [2, [3,[...]]]]],或者[[[[[...], -4], -3], -2], -1]? 數字表示對應[ ]的維度。當axis位默認表示求全局最大值。

keepdims:默認時,維度會減少1,為True時,保持維度不變。

name:操作名稱

reduction_indices:axis的舊名稱(已經棄用)

示例:

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('************')# 對于二維矩陣,axis=0軸可以理解為行增長方向(向下)即按列求最值,axis=1軸可以理解為列增長方向(向右)按列行求最值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)))

結果:

[[1 2][5 3][2 6]] ************ [2 5 6] ************ [[2][5][6]] ************ [[5 6]]

ps:另外該函數等價于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]

?

總結

以上是生活随笔為你收集整理的tf.reduce_max()函数的用法详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。