TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
polygamma()用於計算多伽瑪函數。 Polygamma函數定義為:
僅針對非負整數階定義此函數,即a的值應為非負整數。
用法:tensorflow.math.polygamma( a, x, name)
參數:
- a:它是非負值的張量。允許的dty是float32,float64。
- x:它是與dtype相同的張量
- name(optional):它定義了操作的名稱。
返回值:
它返回與a相同dtype的張量。
範例1:
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([1, 2, 3], dtype = tf.float64)
x = tf.constant([7, 9, 13], dtype = tf.float64)
# Printing the input tensor
print('a:', a)
print('x:', x)
# Calculating result
res = tf.math.polygamma(a, x)
# Printing the result
print('Result:', res)
輸出:
a: tf.Tensor([1. 2. 3.], shape=(3, ), dtype=float64) x: tf.Tensor([ 7. 9. 13.], shape=(3, ), dtype=float64) Result: tf.Tensor([ 0.15354518 -0.01379332 0.00102074], shape=(3, ), dtype=float64)
範例2:對於負值,返回的輸出是nan。
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([-1, 2, 3], dtype = tf.float64)
x = tf.constant([7, 9, 13], dtype = tf.float64)
# Printing the input tensor
print('a:', a)
print('x:', x)
# Calculating Result
res = tf.math.polygamma(a, x)
# Printing the result
print('Result:', res)
輸出:
a: tf.Tensor([-1. 2. 3.], shape=(3, ), dtype=float64) x: tf.Tensor([ 7. 9. 13.], shape=(3, ), dtype=float64) Result: tf.Tensor([ nan -0.01379332 0.00102074], shape=(3, ), dtype=float64)
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.polygamma()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。