📜  Python – tensorflow.math.segment_min()

📅  最后修改于: 2022-05-13 01:54:40.960000             🧑  作者: Mango

Python – tensorflow.math.segment_min()

TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

segment_min()用于查找张量段中的最小元素。

示例 1:

Python3
# importing the library
import tensorflow as tf
  
# Initializing the input tensor
data = tf.constant([1, 2, 3])
segment_ids = tf.constant([2, 2, 2])
  
# Printing the input tensor
print('data: ', data)
print('segment_ids: ', segment_ids)
  
# Calculating result
res = tf.math.segment_min(data, segment_ids)
  
# Printing the result
print('Result: ', res)


Python3
# importing the library
import tensorflow as tf
  
# Initializing the input tensor
data = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype = float64)
segment_ids = tf.constant([0, 0, 2])
  
# Printing the input tensor
print('data: ', data)
print('segment_ids: ', segment_ids)
  
# Calculating result
res = tf.math.segment_min(data, segment_ids)
  
# Printing the result
print('Result: ', res)


输出:

data:  tf.Tensor([1 2 3], shape=(3, ), dtype=int32)
segment_ids:  tf.Tensor([2 2 2], shape=(3, ), dtype=int32)
Result:  tf.Tensor([0 0 1], shape=(3, ), dtype=int32)



示例 2:

Python3

# importing the library
import tensorflow as tf
  
# Initializing the input tensor
data = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype = float64)
segment_ids = tf.constant([0, 0, 2])
  
# Printing the input tensor
print('data: ', data)
print('segment_ids: ', segment_ids)
  
# Calculating result
res = tf.math.segment_min(data, segment_ids)
  
# Printing the result
print('Result: ', res)

输出:

data:  tf.Tensor(
[[1. 2. 3.]
 [4. 5. 6.]
 [7. 8. 9.]], shape=(3, 3), dtype=float64)
segment_ids:  tf.Tensor([0 0 2], shape=(3, ), dtype=int32)
Result:  tf.Tensor(
[[1.  2.  3. ]
 [0.  0.  0. ]
 [7.  8.  9. ]], shape=(3, 3), dtype=float64)