[Pythonmac-SIG] Bug in Numeric?
Chris Barker
Chris.Barker@noaa.gov
Mon, 16 Sep 2002 11:49:01 -0700
Chris Lee wrote:
> >>> import Numeric
> >>> t = open("Macintosh HD:Users:cjl:Desktop:100902teu:00")
> >>> g = t.read()
all is well here. You now have a string with your data in it.
> >>> g = Numeric.reshape(g,(512,512))
You shouldn't expect this to work. reshape() takes an array as the first
argument. You have passed it a string.
> >>> h = Numeric.array(g, 'I')
> following which MacPython hard crashes...
I wouldn't expect this to work either. the array() constuctor expects a
sequence of numbers (or maybe charactors, for type 'c'). HOwever, it
shouldn't hard crash, either...
What I think you want to do is take the data in a string, and make an
array out of it. Use the fromstring() function:
g = Numeric.fromstring(g,'b') # I thinkyou want 'b' as it sounds like
you data is single byte unsigned integers.
g.shape = (512,512)
should do it.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov