在Python中用一个切比雪夫数列除以另一个数列
在这篇文章中,我们将研究一种在Python中用一个切比雪夫数列除以另一个数列的方法。
切比雪夫多项式的线性组合被称为切比雪夫系列。切比雪夫多项式从来不是正式生成的。在所有的计算中只需要系数。在这篇文章中,让我们看看如何用一个切比雪夫级数除以另一个级数。Numpy库为我们提供了numpy.polynomial.chebyshev.chebdiv()方法,用于除掉两个切比雪夫数列。
语法: numpy.polynomial.chebyshev.chebdiv(c1, c2)
参数:
- c1:类似阵列的对象。切比雪夫级数系数从低到高排列在一个一维阵列中。
- c2:类似数组的对象。商和余数由切比雪夫级数系数表示。
返回:
除法后,返回一个数组。
示例 1:
我们导入NumPy包。我们创建两个数组,c1是切比雪夫数列系数从低到高排列的一维数组。c2是商,余数由切比雪夫数列系数表示。Chev.chebdiv()是用来划分两个切比雪夫数列的函数。数组的形状由.shape属性找到,数组的尺寸由.ndim属性找到,数组的数据类型是.type属性。
# import packages
import numpy as np
from numpy.polynomial import chebyshev as Chev
# Creating arrays of coefficients
array = np.array([3, 1, 4])
array2 = np.array([5, 7, 9])
print(array)
print(array2)
# shape of the arrays
print("Shape of the array1 is : ", array.shape)
print("Shape of the array2 is : ", array2.shape)
# dimensions of the array
print("The dimension of the array1 is : ", array.ndim)
print("The dimension of the array2 is : ", array2.ndim)
# Datatype of the arrays
print("Datatype of our Array1 is : ", array.dtype)
print("Datatype of our Array2 is : ", array2.dtype)
# dividing Chebyshev series
print(Chev.chebdiv(array, array2))
输出:
[3 1 4]
[5 7 9]
Shape of the array1 is : (3,)
Shape of the array2 is : (3,)
The dimension of the array1 is : 1
The dimension of the array2 is : 1
Datatype of our Array1 is : int64
Datatype of our Array2 is : int64
(array([0.44444444]), array([ 0.77777778, -2.11111111]))
示例 2:
在这个例子中,商和余数都不是 “直观 “的,我们在python中进一步将切比雪夫级数除以另一个。
# import packages
import numpy as np
from numpy.polynomial import chebyshev as Chev
# Creating arrays of coefficients
# neither quotient and remainder "intuitive"
array = np.array([11, 22, 33])
array2 = np.array([1, 11, 22, 33])
print(array)
print(array2)
# shape of the arrays
print("Shape of the array1 is : ", array.shape)
print("Shape of the array2 is : ", array2.shape)
# dimensions of the array
print("The dimension of the array1 is : ", array.ndim)
print("The dimension of the array2 is : ", array2.ndim)
# Datatype of the arrays
print("Datatype of our Array1 is : ", array.dtype)
print("Datatype of our Array2 is : ", array2.dtype)
# dividing Chebyshev series
print(Chev.chebdiv(array2, array))
输出:
[11 22 33]
[ 1 11 22 33]
Shape of the array1 is : (3,)
Shape of the array2 is : (4,)
The dimension of the array1 is : 1
The dimension of the array2 is : 1
Datatype of our Array1 is : int64
Datatype of our Array2 is : int64
(array([0., 2.]), array([-21., -44.]))