Python – tensorflow.math.zero_fraction()
Last Updated :
10 Mar, 2023
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
import tensorflow as tf
a = tf.constant([ 5 , 0 , 9 , 15 ], dtype = tf.float64)
print ( 'a: ' , a)
res = tf.math.zero_fraction(a)
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
import tensorflow as tf
a = tf.constant([ 5 + 3j , 0 + 0j , 9 - 6j , 0 + 0j ], dtype = tf.complex128)
print ( 'a: ' , a)
res = tf.math.zero_fraction(a)
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...