在Python中使用NumPy将一个赫米特数列除以另一个数列

在Python中使用NumPy将一个赫米特数列除以另一个数列

在这篇文章中,我们将看到如何在Python中使用NumPy将一个Hermite数列除以另一个。

numpy hermdiv()方法帮助我们用一个Hermite数列除以另一个。两个Hermite数列的商和余数,c1 / c2,将被返回。参数是一系列的系数,从最低阶到最高阶的 “项”,例如,[1,4,3]代表P 0 + 4*P 1 + 3*P 2。

语法: numpy.polynomial.hermite.hermdiv(c1, c2)

参数:

  • c1, c2:类似数组的对象。赫米特数列系数从低到高排列在一个一维数组中。

返回:quotient, remainder:ndarrays.商和余数用Hermite系列系数表示。

示例 1:

在这个例子中,我们使用np.array()方法创建了两个代表系数的数字数组。系数应该从低到高。数组的形状由.shape属性定义,数组的尺寸由.ndim定义,数组的数据类型由.type属性返回。hermite.hermdiv()方法用来除以两个Hermite数列,并返回结果。将返回两个数组。首先是商数组,然后是余数组。

# import package
import numpy as np
 
# Creating arrays of coefficients
array = np.array([1, 5, 7])
array2 = np.array([2, 3, 5])
print(array)
print(array2)
 
# shape of the array is
print("Shape of the array1 is : ",
      array.shape)
print("Shape of the array2 is : ",
      array2.shape)
 
# dimension of the array
print("The dimension of the array1 is : ",
      array.ndim)
print("The dimension of the array2 is : ",
      array2.ndim)
 
# Datatype of the array
print("Datatype of our Array is : ",
      array.dtype)
print("Datatype of our Array2 is : ",
      array2.dtype)
 
# dividing two hermite series
print("Division of two hermite series : ",
      np.polynomial.hermite.hermdiv(array,
                                    array2))

输出:

[1 5 7]

[2 3 5]

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 Array is : int64

Datatype of our Array2 is : int64

Division of two hermite series : (array([1.4]), array([-1.8, 0.8]))

示例 2:

在这个例子中,我们给出了相同的数组作为系数,因为预期的商是1,余数是0。

# import package
import numpy as np
 
# Creating arrays of coefficients
array = np.array([1, 5, 7])
array2 = np.array([2, 3, 5])
print(array)
print(array2)
 
# shape of the array is
print("Shape of the array1 is : ",
      array.shape)
print("Shape of the array2 is : ",
      array2.shape)
 
# dimension of the array
print("The dimension of the array1 is : ",
      array.ndim)
print("The dimension of the array2 is : ",
      array2.ndim)
 
# Datatype of the array
print("Datatype of our Array is : ",
      array.dtype)
print("Datatype of our Array2 is : ",
      array2.dtype)
 
# dividing two hermite series
print("Division of two hermite series : ",
      np.polynomial.hermite.hermdiv(array,
                                    array2))

输出:

[1 2 3]

[1 2 3]

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 Array is : int64

Datatype of our Array2 is : int64

Division of two hermite series : (array([1.]), array([0.]))

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 多项式