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