TensorFlow是Google設計的開源python庫,用於開發機器學習模型和深度學習神經網絡。 argmax()是tensorflow數學模塊中存在的方法。此方法用於查找軸上的最大值。
用法: tensorflow.math.argmax( input,axes,output_type,name ) Arguments: 1. input:It is a tensor. Allowed dtypes for this tensor are float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64. 2. axes: It is also a vector. It describes the axes to reduce the tensor. Allowed dtype are int32 and int64. Also [-rank(input),rank(input)) is the range allowed. axes=0 is used for vector. 3. output_type: It defines the dtype in which returned result should be. Allowed values are int32, int64 and the default value is int64. 4. name: It is an optional argument which defines name for the operation. 返回: A tensor of output_type which contains the indices of the maximum value along the axes.
範例1:
Python3
# importing the library
import tensorflow as tf
# initializing the constat tensor
a = tf.constant([5,10,5.6,7.9,1,50]) # 50 is the maximum value at index 5
# getting the maximum value index tensor
b = tf.math.argmax(input = a)
# printing the tensor
print('tensor:',b)
# Evaluating the value of tensor
c = tf.keras.backend.eval(b)
#printing the value
print('value:',c)
輸出:
tensor: tf.Tensor(5, shape=(), dtype=int64) value:5
範例2:
本示例使用shape(3,3)的張量。
Python3
# importing the library
import tensorflow as tf
# initializing the constat tensor
a = tf.constant(value = [9,8,7,3,5,4,6,2,1],shape = (3,3))
# printing the initialized tensor
print(a)
# getting the maximum value indices tensor
b = tf.math.argmax(input = a)
# printing the tensor
print('Indices Tensor:',b)
# Evaluating the tesor value
c = tf.keras.backend.eval(b)
# printing the value
print('Indices:',c)
輸出:
tf.Tensor( [[9 8 7] [3 5 4] [6 2 1]], shape=(3, 3), dtype=int32) Indices tensor:tf.Tensor([0 0 0], shape=(3,), dtype=int64) Indices:[0 0 0] # maximum value along the axes are 9,8,7 at indices 0,0,0 respectively.
相關用法
- Python set()用法及代碼示例
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python os.minor()用法及代碼示例
- Python os.major()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python os.truncate()用法及代碼示例
- Python os.ftruncate()用法及代碼示例
- Python cmath.log()用法及代碼示例
- Python shutil.which()用法及代碼示例
- Python os.makedev()用法及代碼示例
- Python os.sched_get_priority_max()用法及代碼示例
- Python os.sched_get_priority_min()用法及代碼示例
- Python os.sched_setaffinity()用法及代碼示例
- Python sympy.S()用法及代碼示例
- Python os.setgroups()用法及代碼示例
- Python os.lchown()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python | tensorflow.math.argmax() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。