[Numpy-discussion] Unpleasant behavior with poly1d and numpy scalar multiplication
Charles R Harris
Sat Feb 13 11:24:40 CST 2010
On Sat, Feb 13, 2010 at 10:04 AM, Fernando Perez <email@example.com>wrote:
> On Sat, Feb 13, 2010 at 10:34 AM, Charles R Harris
> <firstname.lastname@example.org> wrote:
> > The new polynomials don't have that problem.
> > In : from numpy.polynomial import Polynomial as Poly
> > In : p = Poly([1,2])
> Aha, great! Many thanks, I can tell my students this, and just show
> them the caveat of calling float(x) on any scalar they want to use
> with the 'old' ones for now.
> I remember being excited about your work on the new Polys, but since
> I'm teaching with stock 1.3, I hadn't found them recently and just
> forgot about them. Excellent.
> One minor suggestion: I think it would be useful to have the new
> polys have some form of pretty-printing like the old ones. It is
> actually useful when working, to verify what one has at hand, to see
> an expanded printout like the old ones do:
I thought about that, but decided it was best left to a derived class, say
PrettyPoly ;) Overriding __repr__ and __str__ is an example where
inheritance makes sense.
> In : p_old = numpy.poly1d([3, 2, 1])
> In : p_old
> Out: poly1d([3, 2, 1])
> In : print(p_old)
> 3 x + 2 x + 1
> Just yesterday I was validating some code against a symbolic
> construction with sympy, and it was handy to pretty-print them; I also
> think it makes them much easier to grasp for students new to the
> In any case, thanks both for the tip and especially the code contribution!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion