Python – tensorflow.math.is_finite()

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. 

is_finite() se usa para verificar la finitud de los elementos de x.

Sintaxis: tensorflow.math.is_finite(x, nombre)

Parámetros:

  • x: Es un tensor. Los dtypes permitidos son bfloat16, half, float32, float64.
  • name(opcional): Define el nombre de la operación

Devuelve: Devuelve un tensor de dtype bool.

Ejemplo 1: este ejemplo usa numpy inf y verifica su finitud.

Python3

# importing the library
import tensorflow as tf
import numpy as np
 
# Initializing the input tensor
a = tf.constant([7, 8, 13, 11, np.inf], dtype = tf.float64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating the result
res = tf.math.is_finite(a)
 
# Printing the result
print('Result: ', res)

Producción:

a:  tf.Tensor([ 7.  8. 13. 11. inf], shape=(5, ), dtype=float64)
Result:  tf.Tensor([ True  True  True  True False], shape=(5, ), dtype=bool)

Ejemplo 2: este ejemplo usa numpy nan y verifica su finitud.

Python3

# Importing the library
import tensorflow as tf
import numpy as np
 
# Initializing the input tensor
a = tf.constant([7, 8, 13, 11, np.nan], dtype = tf.float64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating the result
res = tf.math.is_finite(a)
 
# Printing the result
print('Result: ', res)

Producción:

a:  tf.Tensor([ 7.  8. 13. 11. nan], shape=(5, ), dtype=float64)
Result:  tf.Tensor([ True  True  True  True False], shape=(5, ), dtype=bool)

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 *