TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
reduce_max()用於在張量維度上查找元素的最大值。
用法:tensorflow.math.reduce_max( input_tensor, axis, keepdims, name)
參數:
- input_tensor:是減少的數字張量。
- axis(optional):它表示要縮小的尺寸。其值應在[-rank(input_tensor),rank(input_tensor))範圍內。如果對此沒有給出值,則所有尺寸都會減小。
- keepdims(optional):默認值為False。如果將其設置為True,它將保留長度為1的縮小尺寸。
- name(optional):它定義了操作的名稱。
返回值:它返回一個張量。
範例1:
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([1, 2, 3, 4], dtype = tf.float64)
# Printing the input tensor
print('Input:', a)
# Calculating result
res = tf.math.reduce_max(a)
# Printing the result
print('Result:', res)
輸出:
Input: tf.Tensor([1. 2. 3. 4.], shape=(4, ), dtype=float64) Result: tf.Tensor(4.0, shape=(), dtype=float64)
範例2:
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([[1, 2], [3, 4]], dtype = tf.float64)
# Printing the input tensor
print('Input:', a)
# Calculating result
res = tf.math.reduce_max(a, axis = 1, keepdims = True)
# Printing the result
print('Result:', res)
輸出:
Input: tf.Tensor( [[1. 2.] [3. 4.]], shape=(2, 2), dtype=float64) Result: tf.Tensor( [[2.] [4.]], shape=(2, 1), dtype=float64)
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.reduce_max()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。