📜  numpy.roots()函数Python

📅  最后修改于: 2022-05-13 01:54:59.850000             🧑  作者: Mango

numpy.roots()函数Python

numpy.roots()函数返回多项式的根,其系数在 p 中给出。 rank-1 数组 p 中的值是多项式的系数。如果 p 的长度为 n+1,则多项式描述为: p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]

代码#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)

输出 :

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


代码#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)

输出 :

[-0.3125+0.46351241j -0.3125-0.46351241j]