当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Numpy np.leggauss()用法及代码示例


np.leggauss()计算Gauss-legendre正交的采样点和权重。这些采样点和权重将正确积分度的多项式2*deg - 1 在间隔内或更少[-1, 1]配重函数f(x) = 1

用法: np.leggauss(deg)
参数:
deg :[int] Number of sample points and weights. It must be >= 1.

返回:1. [ndarray]包含样本点的一维ndarray。
2. [ndarray]包含权重的一维ndarray。


代码1:

# Python program explaining 
# numpy.leggauss() method  
    
# importing numpy as np   
# and numpy.polynomial.legendre module as geek  
import numpy as np  
import numpy.polynomial.legendre as geek 
    
# Input degree = 2 
  
degree = 2 
     
# using np.leggauss() method  
res = geek.leggauss(degree)  
  
# Resulting array of sample point and weight 
print (res) 
输出:
(array([-0.57735027,  0.57735027]), array([ 1.,  1.]))

代码2:

# Python program explaining 
# numpy.leggauss() method  
    
# importing numpy as np   
# and numpy.polynomial.legendre module as geek  
import numpy as np  
import numpy.polynomial.legendre as geek 
    
# Input degree 
degree = 3
    
# using np.leggauss() method  
res = geek.leggauss(degree)  
  
# Resulting array of sample point and weight 
print (res) 
输出:
(array([-0.77459667,  0.,  0.77459667]), array([ 0.55555556,  0.88888889,  0.55555556]))


相关用法


注:本文由纯净天空筛选整理自jana_sayantan大神的英文原创作品 Python | Numpy np.leggauss() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。