Wednesday, August 27, 2025
HomeLanguagesnumpy.roots() function – Python

numpy.roots() function – Python

numpy.roots() function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + … + p[n-1]*x + p[n]

Syntax : numpy.roots(p)

Parameters :
p : [array_like] Rank-1 array of polynomial coefficients.

Return : [ndarray] An array containing the roots of the polynomial.

Code #1 :




# Python program explaining
# numpy.roots() function
      
# importing numpy as geek 
import numpy as geek 
  
p = [1, 2, 3]
  
gfg = geek.roots(p)
  
print (gfg)


Output :

[-1.+1.41421356j -1.-1.41421356j]

 
Code #2 :




# Python program explaining
# numpy.roots() function
       
# importing numpy as geek 
import numpy as geek 
   
p = [3.2, 2, 1]
   
gfg = geek.roots(p)
   
print (gfg)


Output :

[-0.3125+0.46351241j -0.3125-0.46351241j]
RELATED ARTICLES

Most Popular

Dominic
32236 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6609 POSTS0 COMMENTS
Nicole Veronica
11779 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11828 POSTS0 COMMENTS
Shaida Kate Naidoo
6719 POSTS0 COMMENTS
Ted Musemwa
7002 POSTS0 COMMENTS
Thapelo Manthata
6678 POSTS0 COMMENTS
Umr Jansen
6690 POSTS0 COMMENTS