Open In App

Python - tensorflow.math.polyval()

Last Updated : 11 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

polyval() is used to compute element wise value of polynomial.

Syntax: tensorflow.math.polyval( coeffs, x, name)

Parameters:

  • coeffs: It is a list tensor which represents the coefficients of the polynomial.
  • x: It is a tensor which represents the variable of the polynomial.
  • name(optional): It defines the name for the operation.

Returns: It returns a tensor.

If coeffs is a tensor with n values and x is a tensor then P(x) is nth order polynomial which is defined as:

p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1)

Example 1:

Python3
# importing the library
import tensorflow as tf

# Initializing the input tensor
coeffs = [-1, 2, 3]
x = tf.constant([7], dtype = tf.int32)

# Printing the input tensor
print('coeffs: ', coeffs)
print('x: ', x)

# Calculating Result
res = tf.math.polyval(coeffs, x)

# Printing the result
print('Result: ', res)

Output:

coeffs:  [-1, 2, 3]
x:  tf.Tensor([7], shape=(1, ), dtype=int32)
Result:  tf.Tensor([-32], shape=(1, ), dtype=int32)


Example 2:

Python3
# importing the library
import tensorflow as tf

# Initializing the input tensor
coeffs = [-1, 2, 3]
x = tf.constant([7, 2], dtype = tf.int32)

# Printing the input tensor
print('coeffs: ', coeffs)
print('x: ', x)

# Calculating Result
res = tf.math.polyval(coeffs, x)

# Printing the result
print('Result: ', res)

Output:

coeffs:  [-1, 2, 3]
x:  tf.Tensor([7 2], shape=(2, ), dtype=int32)
Result:  tf.Tensor([-32   3], shape=(2, ), dtype=int32)

Next Article
Practice Tags :

Similar Reads