📜  Python – tensorflow.math.polyval()

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

Python – tensorflow.math.polyval()

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

polyval()用于计算多项式的元素值。

如果 coeffs 是具有 n 个值的张量并且 x 是张量,则 P(x) 是 n 阶多项式,其定义为:

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

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


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)


输出:

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


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

输出:

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