HomeLanguagesPython – tensorflow.math.zero_fraction()

Python – tensorflow.math.zero_fraction()

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

zero_fraction() is used to find fraction of zeros in value.

Syntax: tensorflow.math.zero_fraction(value, name)

Parameters:

  • value: It’s a tensor of numeric type.
  • name(optional): It defines the name for the operation.

Returns: It returns fraction of zeros in value, with dtype float32.

Example 1:

Python3




# importing the library
import tensorflow as tf
 
# Initializing the input tensor
a = tf.constant([ 5, 0, 9, 15], dtype = tf.float64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating result
res = tf.math.zero_fraction(a)
 
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([ 5.  0.  9. 15.], shape=(4, ), dtype=float64)
Result:  tf.Tensor(0.25, shape=(), dtype=float32)

Example 2:

Python3




# importing the library
import tensorflow as tf
 
# Initializing the input tensor
a = tf.constant([ 5 + 3j, 0 + 0j, 9-6j, 0 + 0j], dtype = tf.complex128)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating result
res = tf.math.zero_fraction(a)
 
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([5.+3.j 0.+0.j 9.-6.j 0.+0.j], shape=(4, ), dtype=complex128)
Result:  tf.Tensor(0.5, shape=(), dtype=float32)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32708 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7081 POSTS0 COMMENTS
Nicole Veronica
12218 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12307 POSTS0 COMMENTS
Shaida Kate Naidoo
7201 POSTS0 COMMENTS
Ted Musemwa
7460 POSTS0 COMMENTS
Thapelo Manthata
7182 POSTS0 COMMENTS
Umr Jansen
7166 POSTS0 COMMENTS