Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Numeric + wxPython, can't understand a bug...

Reply
Thread Tools

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

 
 
John Ladasky
Guest
Posts: n/a
 
      04-28-2007
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 |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      04-28-2007
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

 
Reply With Quote
 
 
 
 
John Ladasky
Guest
Posts: n/a
 
      04-28-2007
On Apr 27, 9:40 pm, Robert Kern <(E-Mail Removed)> 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 |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int to numeric numeric(18,2) ? jobs ASP .Net 2 07-22-2007 12:32 AM
Arithmetic overflow error converting numeric to data type numeric. darrel ASP .Net 4 07-19-2007 09:57 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM
Latches in pipeline design and numeric logic andyesquire@hotmail.com VHDL 3 04-06-2005 11:57 AM



Advertisments