Friday, September 5, 2025
HomeLanguagesPython – tensorflow.math.is_finite()

Python – tensorflow.math.is_finite()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

is_finite() is used to check element wise finiteness of x.

Syntax: tensorflow.math.is_finite( x, name)

Parameters:

  • x: It is a tensor. Allowed dtypes are bfloat16, half, float32, float64.
  • name(optional): It defines the name of the operation

Returns: It returns a tensor of dtype bool.

Example 1:This example uses numpy inf and checks it finiteness.

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)


Output:

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

Example 2: This example uses numpy nan and checks it finiteness.

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)


Output:

a:  tf.Tensor([ 7.  8. 13. 11. nan], shape=(5, ), dtype=float64)
Result:  tf.Tensor([ True  True  True  True False], shape=(5, ), dtype=bool)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS