Friday, October 17, 2025
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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS