Python – tensorflow.math.segment_prod()

TensorFlow es una biblioteca Python de código abierto diseñada por Google para desarrollar modelos de aprendizaje automático y redes neuronales de aprendizaje profundo.

segment_prod() se usa para encontrar el producto de elementos en segmentos de un tensor.

Sintaxis: tensorflow.math.segment_prod (datos, segment_ids, nombre)

Parámetro:

  • datos: Es un tensor. Los dtypes permitidos son float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  • segment_ids: es un tensor 1-D con valores ordenados. Su tamaño debe ser igual al tamaño de la primera dimensión de los datos. Los dtypes permitidos son int32 e int64.
  • name(opcional): Define el nombre de la operación.

Retorno: Devuelve un tensor de tipo d como x.

Ejemplo 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_prod(data, segment_ids)
  
# Printing the result
print('Result: ', res)

Producción:

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



Ejemplo 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_prod(data, segment_ids)
  
# Printing the result
print('Result: ', res)

Producción:

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(
[[ 4. 10. 18.]
 [ 1.  1.  1.]
 [ 7.  8.  9.]], shape=(3, 3), dtype=float64)

Publicación traducida automáticamente

Artículo escrito por aman neekhara y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *