在Python中使用NumPy将一个赫米特数列添加到另一个数列上
在这篇文章中,我们将介绍如何使用Python中的NumPy将一个Hermite数列添加到另一个数列。
np.polynomial.hermite.hermadd 方法
NumPy库中的numpy.polynomial.hermite.hermadd()方法用于将一个Hermite数列添加到另一个数列中。返回两个Hermite数列的总和(c1 + c2)。参数是系数序列,从低到高的顺序,例如,[4,3,1]表示系列4P 0 + 3P 1 + 1*P 2。
语法: polynomial.hermite.hermadd(c1, c2)
参数:
- c1,c2:类似数组的对象。赫米特级数的系数从低到高排列在一个一维数组中。
返回:数组,代表它们之和的Hermite系列。
示例 1:
numpy.polynomial.hermite_e.hermadd()被用来将一个Hermite数列添加到另一个数列中。系数数组的形状由.shape属性决定,数组的尺寸由.ndim属性决定,数组的数据类型由.type属性决定。该方法将系数数组作为输入,并将Hermite数列的总和作为输出。
# import packages
import numpy as np
from numpy.polynomial import hermite_e as H
# array1 coefficients
array1 = np.array([1,2,3,4,5])
print(array1)
# array2 coefficients
array2 = np.array([6,7,8,9,10])
print(array2)
# shape of the arrays are
print("Shape of array1 is: ", array1.shape)
print("Shape of array1 is: ", array2.shape)
# dimensions of the array
print("The dimension of array1 is: ", array1.ndim)
print("The dimension of array2 is: ", array2.ndim)
# adding two hermite series
print('addition of the two hermite series : ')
print(H.hermeadd(array1,array2))
输出:
[1 2 3 4 5]
[ 6 7 8 9 10]
Shape of array1 is: (5,)
Shape of array1 is: (5,)
The dimension of array1 is: 1
The dimension of array2 is: 1
addition of the two hermite series :
[ 7. 9. 11. 13. 15.]
示例 2:
在这个例子中,我们给出了不同形状的数组作为输入,两个Hermite数列的相加并不需要数组的系数形状相似。
# import packages
import numpy as np
from numpy.polynomial import hermite_e as H
# array1 coefficients
array1 = np.array([1,2,3,4,5])
print(array1)
# array2 coefficients
array2 = np.array([6,7,8,9])
print(array2)
# shape of the arrays are
print("Shape of array1 is: ", array1.shape)
print("Shape of array1 is: ", array2.shape)
# dimensions of the array
print("The dimension of array1 is: ", array1.ndim)
print("The dimension of array2 is: ", array2.ndim)
# adding two hermite series
print('addition of the two hermite series : ')
print(H.hermeadd(array1,array2))
输出:
[1 2 3 4 5]
[6 7 8 9]
Shape of array1 is: (5,)
Shape of array1 is: (4,)
The dimension of array1 is: 1
The dimension of array2 is: 1
addition of the two hermite series :
[ 7. 9. 11. 13. 5.]