Python ``tensorflow.math.polygamma()`` 函数与实例


发布日期 : 2021-07-07 02:09:20 UTC

访问量: 10 次浏览

Python – tensorflow.math.polygamma()

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

polygamma()是用来计算polygamma函数的。Polygamma函数定义为:。

Python – tensorflow.math.polygamma()")

这个函数只为非负的整数订单定义,即a的值应该是非负的。

语法:
tensorflow.math.polygamma( a, x, name)

参数:

  • a:它是一个非负值的张量。允许的张量是 float32, float64。
  • x:它是一个与a的d类型相同的张量。
  • name(可选):它定义了该操作的名称。

返回值:

它返回一个与a的d类型相同的张量。

示例 1:

# 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。

# 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)