当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python tensorflow.math.argmin()用法及代码示例


TensorFlow是Google设计的开源python库,用于开发机器学习模型和深度学习神经网络。 argmin()是tensorflow数学模块中存在的方法。此方法用于查找轴上的最小值。

用法:
tensorflow.math.argmin(
    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 minimum 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]) # 1 is the minimum value at index 4 
  
# getting the minimum value index tensor 
b = tf.math.argmin(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(4, shape=(), dtype=int64)
value:4

范例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 minimum value indices tensor 
b = tf.math.argmin(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([1 2 2], shape=(3,), dtype=int64)
 Indices:[1 2 2]



相关用法


注:本文由纯净天空筛选整理自aman neekhara大神的英文原创作品 Python | tensorflow.math.argmin() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。