Wednesday, November 27, 2024
Google search engine
HomeLanguagesPython – tensorflow.math.is_nan()

Python – tensorflow.math.is_nan()

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

is_nan() returns true if element is NaN otherwise it returns false.

Syntax: tensorflow.math.is_NaN( 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:

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_nan(a)
 
# Printing the result
print('Result: ', res)


Output:

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

Example 2: This example uses numpy nan.

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_nan(a)
 
# Printing the result
print('Result: ', res)


Output:

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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments