首页 > 编程语言 >在 Python 中将一个 Legendre 系列添加到另一个 Legendre 系列

在 Python 中将一个 Legendre 系列添加到另一个 Legendre 系列

时间:2023-01-28 18:33:42浏览次数:40  
标签:... 系列 Python Array1 c2 print Legendre c1


要将一个 Legendre 系列添加到另一个系列,请使用 Python 中的 polynomial.legendre.legadd() 方法 嘟嘟。该方法返回一个数组,表示其总和的勒让德系列。

返回两个勒让德系列 c1 + c2 的总和。参数是系数序列 从低阶项到最高项排序,即 [1,2,3] 表示序列 P_0 + 2*P_1 + 3*P_2。 参数 c1 和 c2 是勒让德级数系数的一维数组,从低到高排序。

步骤

首先,导入所需的库 -


import numpy as np
from numpy.polynomial import laguerre as L


创建勒让德级数系数的一维数组 −


c1 = np.array([2,3,4])
c2 = np.array([4,3,2])


显示系数数组 −


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)


要将一个 Legendre 系列添加到另一个系列,请使用 Python Numpy 中的 polynomial.legendre.legadd() 方法。该方法返回一个数组,表示其总和的勒让德级数 -


print("\nResult (sum)....\n",L.legadd(c1, c2))




import numpy as np from numpy.polynomial import legendre as L # Create 1-D arrays of Legendre series coefficients c1 = np.array([2,3,4]) c2 = np.array([4,3,2]) # Display the arrays of coefficients print("Array1...\n",c1) print("\nArray2...\n",c2) # Display the datatype print("\nArray1 datatype...\n",c1.dtype) print("\nArray2 datatype...\n",c2.dtype) # Check the Dimensions of both the arrays print("\nDimensions of Array1...\n",c1.ndim) print("\nDimensions of Array2...\n",c2.ndim) # Check the Shape of both the arrays print("\nShape of Array1...\n",c1.shape) print("\nShape of Array2...\n",c2.shape) # To add one Legendre series to another, use the polynomial.legendre.legadd() method in Python Numpy # The method returns an array representing the Legendre series of their sum. print("\nResult (sum)....\n",L.legadd(c1, c2))

输出


Array1...
[2 3 4]

Array2...
[4 3 2]

Array1 datatype...
int64

Array2 datatype...
int64

Dimensions of Array1...
1

Dimensions of Array2...
1

Shape of Array1...
(3,)

Shape of Array2...
(3,)

Result (sum)....
[6. 6. 6.]

标签:...,系列,Python,Array1,c2,print,Legendre,c1
From: https://blog.51cto.com/10zhancom/6025079

相关文章

  • 为什么你应该使用NumPy数组而不是嵌套的Python列表?
    在本文中,我们将向您展示为什么使用NumPy数组而不是嵌套的Python列表,以及它们之间的异同。PythonNumPyLibraryNumPy是一个Python库,旨在有效地处理Python中的数组。它快......
  • Python更适合某些编程需求吗?
    在本文中,我们将讨论Python是否更适合某些编程需求?比如竞争性编码。答案是肯定的;Python更适合编码。它在短时间内用更少的行数编写代码。基于产品的公司需要优秀的编码人......
  • #Python 数据查询功能,对标V-LOOKUP
    日常办公中,我们经常会遇到需要匹配表,匹配对应数据的场景,在EXCEL中,我们习惯使用VLOOKUP函数或者是X-LOOKUP函数,今天学习的是Python,pandas库中的匹配功能。首先导入所需的pa......
  • python中关于if的规定
    Python程序语言指定任何非0和非空(null)值为true,0或者null为false。翻译过来就是:0,None,""为false,其它都为true。如下代码所示:if__name__=='__main__':ifnot......
  • 【Python】type、isinstance、issubclass详解
    【Python】type、isinstance、issubclass详解大家好,我们的gzh是朝阳三只大明白,满满全是干货,分享近期的学习知识以及个人总结(包括读研和IT),跪求一波关注,希望和大家一起努力、......
  • 【Python】python深拷贝和浅拷贝(一)
    【Python】python深拷贝和浅拷贝(一)大家好,我们的gzh是朝阳三只大明白,满满全是干货,分享近期的学习知识以及个人总结(包括读研和IT),跪求一波关注,希望和大家一起努力、进步!!定义直......
  • 【Python】python深拷贝和浅拷贝(二)
    【Python】python深拷贝和浅拷贝(二)大家好,我们的gzh是朝阳三只大明白,满满全是干货,分享近期的学习知识以及个人总结(包括读研和IT),跪求一波关注,希望和大家一起努力、进步!!前言上......
  • python图片拼接
     首先我们来尝试将分片的图片复原为正常的图片这里是六张切成小细条的图片,原本是一张大图的,现在我们用python将他们合并到一块,题外话图片来源于中华连环画,*http://www......
  • Grafana 系列文章(一):基于 Grafana 的全栈可观察性 Demo
    ......
  • 【Python学习002】函数参数
    我们的gzh是【朝阳三只大明白】,满满全是干货,分享近期的学习知识以及个人总结(包括读研和IT),希望大家一起努力,一起加油!求关注!!概述函数是组织好的、可重复使用的,用来实现单一,或......