📜  Python – tensorflow.math.zero_fraction()

📅  最后修改于: 2022-05-13 01:55:31.419000             🧑  作者: Mango

Python – tensorflow.math.zero_fraction()

TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

zero_fraction()用于查找值中零的分数。

示例 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)


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)


输出:

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




示例 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)

输出:

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)