📜  Python – tensorflow.math.polygamma()

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

Python – tensorflow.math.polygamma()

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

polygamma()用于计算 polygamma函数。多伽马函数定义为:

此函数仅针对非负整数订单定义,即 a 的值应为非负数。

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


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)