Python tensorflow.math.argmin()方法

Python tensorflow.math.argmin()方法

TensorFlow是谷歌设计的开源python库,用于开发机器学习模型和深度学习神经网络。 argmin()是tensorflow数学模块中的一个方法。这个方法是用来寻找整个轴的最小值。

语法:

tensorflow.math.argmin(
    input,axes,output_type,name
)

参数 :
1.input:它是一个张量。这个张量允许的dtypes是 float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64。
2. axes:它也是一个矢量。它描述了用于减少张量的轴。允许的dtype是int32和int64。另外,[-rank(input),rank(input)]是允许的范围。axes=0用于矢量。
3. output_type:它定义了返回结果的dtype。允许的值是int32,int64,默认值是int64。
name:它是一个可选的参数,定义了操作的名称。

返回:
一个output_type的张量,包含沿轴的最小值的索引。

示例 1:

# importing the library
import tensorflow as tf
 
# initializing the constant 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)的张量。

# importing the library
import tensorflow as tf
 
# initializing the constant 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 tensor 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]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Tensorflow 数学函数