Print real roots only in numpy

前端 未结 3 1453
Happy的楠姐
Happy的楠姐 2021-02-05 13:32

I have something like this:

coefs = [28, -36, 50, -22]
print(numpy.roots(coefs))

Of course the result is:

[ 0.35770550+1.117926         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 13:48

    I hope this help.

     roots = np.roots(coeff);
     for i in range(len(roots)):
         if np.isreal(roots[i]):
             print(np.real(roots[i]))
    

提交回复
热议问题