Saturday, January 31, 2026
HomeLanguagesPython | Numpy np.leggauss() method

Python | Numpy np.leggauss() method

np.leggauss() Computes the sample points and weights for Gauss-legendre quadrature. These sample points and weights will correctly integrate polynomials of degree 2*deg - 1 or less over the interval [-1, 1] with the weight function f(x) = 1

Syntax : np.leggauss(deg)
Parameters:
deg :[int] Number of sample points and weights. It must be >= 1.

Return : 1.[ndarray] 1-D ndarray containing the sample points.
2.[ndarray] 1-D ndarray containing the weights.

Code #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) 


Output:

(array([-0.57735027,  0.57735027]), array([ 1.,  1.]))

 

Code #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) 


Output:

(array([-0.77459667,  0.,  0.77459667]), array([ 0.55555556,  0.88888889,  0.55555556]))
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
123 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS