Python – tensorflow.math.polygamma()
Last Updated :
08 Dec, 2022
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
polygamma() is used to compute polygamma function. Polygamma function is defined as:
This function is defined for only non-negative integer orders i.e. value of a should be non-negative.
Syntax: tensorflow.math.polygamma( a, x, name)
Parameters:
- a: It’s a tensor of non-negative values. Allowed dtypes are float32, float64.
- x: It’s a tensor of same dtype as a.
- name(optional): It defines the name for the operation.
Returns:
It returns a tensor of same dtype as a.
Example 1:
Python3
import tensorflow as tf
a = tf.constant([ 1 , 2 , 3 ], dtype = tf.float64)
x = tf.constant([ 7 , 9 , 13 ], dtype = tf.float64)
print ( 'a: ' , a)
print ( 'x: ' , x)
res = tf.math.polygamma(a, x)
print ( 'Result: ' , res)
|
Output:
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)
Example 2: For negative value of a returned output is nan.
Python3
import tensorflow as tf
a = tf.constant([ - 1 , 2 , 3 ], dtype = tf.float64)
x = tf.constant([ 7 , 9 , 13 ], dtype = tf.float64)
print ( 'a: ' , a)
print ( 'x: ' , x)
res = tf.math.polygamma(a, x)
print ( 'Result: ' , res)
|
Output:
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)
Share your thoughts in the comments
Please Login to comment...