On Mon, Dec 12, 2011 at 9:35 AM, <[email protected]> wrote: > On Mon, Dec 12, 2011 at 9:04 AM, LASAGNA DAVIDE > <[email protected]> wrote: >> Hi, >> >> I have written a class for polynomials with negative >> exponents like: >> >> p(x) = a0 + a1*x**-1 + ... + an*x**-n >> >> The code is this one: >> >> class NegativeExpPolynomial( object ): >> def __init__ ( self, coeffs ): >> self.coeffs = np.array( coeffs ) >> >> def __call__( self, x ): >> return sum( (c*x**(-i) for i, c in enumerate( >> self.coeffs ) ) ) > > something like > > self.coeffs = np.asarray(self.coeffs) > > np.sum(self.coeffs * x**(-np.arange(len(self.coeffs))) > > or > np.dot(self.coeffs, x**(-np.arange(len(self.coeffs))) #check > shapes, or np.inner > > Josef > >> >> where coeffs = [a0, a1, ..., an]. >> >> I find that the way i evaluate the polynomial is kind of >> *slow*, especially for polynomial with order larger than >> ~200 and for arrays x large enough.
there might be numerical problems with large polynomials if the range of values is large Josef >> >> Do you have suggestions on how to speed up this code? >> >> Regards, >> >> Davide Lasagna >> >> -- >> Phd Student >> Dipartimento di Ingegneria Aeronautica a Spaziale >> Politecnico di Torino, Italy >> tel: 011/0906871 >> e-mail: [email protected]; [email protected] >> >> _______________________________________________ >> NumPy-Discussion mailing list >> [email protected] >> http://mail.scipy.org/mailman/listinfo/numpy-discussion _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
