Sep-10-2019, 09:25 PM
numpy can do polynomials: https://docs.scipy.org/doc/numpy/referen...mpy.poly1d
Your example,
Your example,
5x^3+2x-5
, would look like this:>>> import numpy >>> eq = numpy.poly1d([5, 0, 2, -5]) >>> print(eq) 3 5 x + 2 x - 5 >>> for i in range(5): ... print(f"x={i}: {eq(i)}") ... x=0: -5 x=1: 2 x=2: 39 x=3: 136 x=4: 323It'll work with any length of polynomial (so yes, x^5 or x^6), since it's based on the length of the list you pass it.