TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
zero_fraction()用於查找零值。
用法:tensorflow.math.softplus(value, name)
參數:
- value:它是數字類型的張量。
- name(optional):它定義了操作的名稱。
返回值:它使用dtype float32返回零值。
範例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)
輸出:
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)
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.zero_fraction()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。