[Numpy-discussion] Unpleasant behavior with poly1d and numpy scalar multiplication

Fernando Perez fperez.net@gmail....
Sat Feb 13 11:04:04 CST 2010


On Sat, Feb 13, 2010 at 10:34 AM, Charles R Harris
<charlesr.harris@gmail.com> wrote:
> The new polynomials don't have that problem.
>
> In [1]: from numpy.polynomial import Polynomial as Poly
>
> In [2]: 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:

In [26]: p_old = numpy.poly1d([3, 2, 1])

In [27]: p_old
Out[27]: poly1d([3, 2, 1])

In [28]: print(p_old)
   2
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
tools.

In any case, thanks both for the tip and especially the code contribution!

Cheers,

f


More information about the NumPy-Discussion mailing list