在python中计算一个埃尔米特级数在点x广播的系数列上的值

在python中计算一个埃尔米特级数在点x广播的系数列上的值

在Python中,将Hermite系列在x点上进行评估可以使用hermite.hermval()方法。第一个参数x,如果x是一个列表或元组,它将被转换为ndarray,否则保持不变,并被视为标量。无论哪种情况,x或其元素必须支持与自身和c的元素的加法和乘法运算。

第二个参数C是一个按顺序排列的系数数组,其中n次项的系数包含在c[n]中。如果c是多维的,剩余的索引对应多个多项式。在二维情况下,可以将系数视为存储在c的列中。

第三个参数tensor如果为True,系数数组的形状在右侧扩展,并添加一个维度,每个维度对应x的维度。对于该操作,标量的维度为0。结果是对c中的每一列都对x的每个元素进行评估。如果为False,则将x广播到c的列进行评估。在c是多维的情况下,此关键字非常有用。默认值为True。

步骤

首先,导入所需的库−

import numpy as np
from numpy.polynomial import hermite as H

创建一个多维数组的系数−

c = np.arange(4).reshape(2,2)

显示数组 –

print("Our Array...\n",c)

检查尺寸 –

print("\nDimensions of our Array...\n",c.ndim)

获取数据类型 −

print("\nDatatype of our Array object...\n",c.dtype)

获取形状 –

print("\nShape of our Array object...\n",c.shape)

要在点x处评估一个Hermite级数,请使用Python的Numpy库中的hermite.hermval()方法 –

print("\nResult...\n",H.hermval([1,2],c, tensor = False))

示例

import numpy as np
from numpy.polynomial import hermite as H

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To evaluate a Hermite series at points x, use the hermite.hermval() method in Python Numpy
print("\nResult...\n",H.hermval([1,2],c, tensor = False))

输出

Our Array...
[[0 1]
[2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
[ 4. 13.]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程