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

Charles R Harris charlesr.harris at gmail.com
Sat Feb 13 22:51:10 EST 2010


On Sat, Feb 13, 2010 at 8:32 PM, Charles R Harris <charlesr.harris at gmail.com
> wrote:

>
>
> On Sat, Feb 13, 2010 at 8:02 PM, Fernando Perez <fperez.net at gmail.com>wrote:
>
>> On Sat, Feb 13, 2010 at 12:24 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>> >> 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.
>>
>> I disagree, I think one of the advantages of having both str and repr
>> is precisely to make it easy to have both a terse,
>> implementation-oriented representation and a more human-friendly one
>>
>
> Note that ipython calls __repr__ to print the output. __repr__ is supposed
> to provide a string that can be used to recreate the object, a pretty
> printed version of __repr__ doesn't provide that. Also, an array or list of
> polynomials, having pretty printed entries looks pretty ugly with the
> newlines and all -- try it with Poly1d. I was also thinking that someone
> might want to provide a better display at some point, drawing on a canvas,
> for instance. And what happens when the degree gets up over 100, which is
> quite reasonable with the Cheybshev polynomials?
>
>

Example:

>>> a
array([   2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
          2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
          2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
          2
1 x + 2 x + 3], dtype=object)
>>> print a
[   2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
    2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
    2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
    2
1 x + 2 x + 3]

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100213/1d7e67df/attachment.html>


More information about the NumPy-Discussion mailing list