Numeric + wxPython, can't understand a bug...

Discussion in 'Python' started by John Ladasky, Apr 28, 2007.

  1. John Ladasky

    John Ladasky Guest

    Hi, folks,

    This probably has to do with Numeric and not with wxPython, but I
    mention both for completeness.

    My OS: Win2000
    Python: 2.3.4
    wx: 2.6.1.0, Unicode version
    Numeric: 23.8


    Here's the minimal code:
    ================================================

    height = 50
    width = 60
    L = []
    for y in range(height):
    for x in range(width):
    L.append(wx.Point(3+(2*x+y%2)*4, 3+7*y))
    print width, height, len(L)
    pos = reshape(array(L), (height, width))



    And here's the output:
    ================================================

    60 50 3000

    pos = reshape(array(L), (height, width))
    ValueError: total size of new array must be unchanged



    I've used exactly this approach to create 2D arrays from lists of
    numbers, with no problems. Why does this fail with wx.Point objects?
    Why is it telling me that I'm changing the array size, when the
    dimensions indicate that I am NOT? Typecasting the array as
    containing PyObject items does not change the error message...

    Thanks for any advice!



    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Ladasky Home Solar, Inc.: blowing sunshine up your |
    | power grid since March 24, 2005. Fiat lux! |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Uptime Downtime kWh generated kWh consumed |
    | 744 days 13 hours 12886 14321 |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
     
    John Ladasky, Apr 28, 2007
    #1
    1. Advertising

  2. John Ladasky

    Robert Kern Guest

    John Ladasky wrote:
    > Hi, folks,
    >
    > This probably has to do with Numeric and not with wxPython, but I
    > mention both for completeness.
    >
    > My OS: Win2000
    > Python: 2.3.4
    > wx: 2.6.1.0, Unicode version
    > Numeric: 23.8
    >
    >
    > Here's the minimal code:
    > ================================================
    >
    > height = 50
    > width = 60
    > L = []
    > for y in range(height):
    > for x in range(width):
    > L.append(wx.Point(3+(2*x+y%2)*4, 3+7*y))
    > print width, height, len(L)
    > pos = reshape(array(L), (height, width))
    >
    >
    >
    > And here's the output:
    > ================================================
    >
    > 60 50 3000
    >
    > pos = reshape(array(L), (height, width))
    > ValueError: total size of new array must be unchanged
    >
    >
    >
    > I've used exactly this approach to create 2D arrays from lists of
    > numbers, with no problems. Why does this fail with wx.Point objects?
    > Why is it telling me that I'm changing the array size, when the
    > dimensions indicate that I am NOT? Typecasting the array as
    > containing PyObject items does not change the error message...


    wx.Point objects are being recognized as sequences by array(). Consequently,
    reshape() thinks you are trying to reshape a (height*width, 2) array into a
    (height, width) array. You might want to create an empty (height, width)
    PyObject array first, and simply assign wx.Point values into it. That bypasses
    array()'s attempt at intuiting the structure of the list.

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Apr 28, 2007
    #2
    1. Advertising

  3. John Ladasky

    John Ladasky Guest

    On Apr 27, 9:40 pm, Robert Kern <> wrote:

    > wx.Point objects are being recognized as sequences by array(). Consequently,
    > reshape() thinks you are trying to reshape a (height*width, 2) array into a
    > (height, width) array. You might want to create an empty (height, width)
    > PyObject array first, and simply assign wx.Point values into it. That bypasses
    > array()'s attempt at intuiting the structure of the list.


    Thanks for the heads-up, Robert. I did as you suggested, and it works
    fine. I'll need to read more about Numeric's array init procedure --
    what it does it not immediately obvious to a newcomer.

    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Ladasky Home Solar, Inc.: blowing sunshine up your |
    | power grid since March 24, 2005. Fiat lux! |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Uptime Downtime kWh generated kWh consumed |
    | 744 days 13 hours 12886 14321 |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
     
    John Ladasky, Apr 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert
    Replies:
    3
    Views:
    741
    Robin Dunn
    Apr 1, 2004
  2. Replies:
    5
    Views:
    948
    X-Centric
    Jun 30, 2005
  3. darrel
    Replies:
    4
    Views:
    835
    darrel
    Jul 19, 2007
  4. jobs

    int to numeric numeric(18,2) ?

    jobs, Jul 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    977
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 22, 2007
  5. Leo Lee
    Replies:
    3
    Views:
    395
    Leo Lee
    Jul 17, 2008
Loading...

Share This Page