问题
from numpy import linalg,dot
import numpy.polynomial.polynomial as poly
x7=poly.Polynomial([1,2])
print x7
according to above code in python it should print 1 + 2x^2, but it is printing poly [1. 2.]. Please help.
回答1:
I'd recommend using numpy.poly1d
and numpy.polymul
, where the coefficients are a0*x2 + a1*x + a2
.
For example, to represent 3*x**2 + 2*x + 1
:
p1 = numpy.poly1d([3,2,1])
therefor for your problem you could use:
p2= numpy.poly1d([2,0,1])
print p2
and printing p2 will represent: 1 + 2x^2
来源:https://stackoverflow.com/questions/33304178/print-polynomial-in-variable-format-in-python