在Python中减去一个Hermite级数
要减去一个Hermite级数,请使用Python Numpy中的polynomial.hermite.hermsub()方法。该方法返回一个数组,表示其差异的Hermite级数。返回两个Hermite级数c1-c2的差异。系数的序列从最低阶开始,一直到最高阶,即[1,2,3]表示系列P_0 + 2P_1 + 3P_2。参数c1和c2是按低到高排序的Hermite系列系数的1-D数组。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import hermite as H
创建Hermite级数系数的一个1-D数组−
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])
显示系数数组−
print("Array1...\n",c1)
print("\nArray2...\n",c2)
显示数据类型−
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)
检查两个数组的维数−
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)
检查两个数组的形状−
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)
要减去一个Hermite级数,请使用Python Numpy中的polynomial.hermite.hermsub()方法−
print("\nResult (difference)....\n",H.hermsub(c1, c2))
例子
import numpy as np
from numpy.polynomial import hermite as H
# 创建Hermite系数的1-D数组
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])
# 显示的系数数组
print("Array1...\n",c1)
print("\nArray2...\n",c2)
# 显示数据类型
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)
# 检查两个数组的维数
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)
# 检查两个数组的形状
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)
# 要减去一个Hermite级数,请使用Python Numpy中的polynomial.hermite.hermsub()方法
# 该方法返回一个数组,表示其差异的Hermite级数
print("\nResult (difference)....\n",H.hermsub(c1, c2))
输出
Array1...
[1 2 3]
Array2...
[3 2 1]
Array1 型态...
int64
Array2 型态...
int64
Array1 维度...
1
Array2 维度...
1
Array1 形状...
(3,)
Array2 形状...
(3,)
Result (difference)....
[-2. 0. 2.]