Converting a list to a Numarray array?
S Timmins
timmins at ltpmail.gsfc.nasa.gov
Wed Feb 26 21:55:05 EST 2003
Alex:
Thanks for your answer but what if the list comes from a file
via split and:
somelist = ['1','2','3']
Then you have to long each element because the list does not contain a
numeric type!
I am also confused about how to ignore certain "records" from a
similar list from reading this file:
#Zip Julian mm dd year icd9 age m/f race <--- NOT in file
03901 2451634 03 30 2000 V3000 0 1 1
03901 2451642 04 07 2000 5990 0 2 1
03901 2451648 04 13 2000 3004 16 2 1
I do this:
input = open(dir+file)
s = input.read()
buf = s.split()
# I really want to select the desired lines here so the code below
# has fewer records to handle.
length = len(buf)/9
Zip = range(length)
for i in xrange(length): Zip[i] = long(buf[long(i)*9])
...
Icd9 = [' ']*length
for i in xrange(length): Icd9[i] = buf[5L+long(i)*9]
...
but wish I could select the lines in buf (assuming it were 2-D) to be
converted and say choose just the "rows" (lines) which contain say the
"V3000" code in the icd9 "field".
Since Python only seems to have 1-D lists it is difficult to "reshape"
buf to a Number of lines by 9 list and then "slice" the icd9 field to
choose just the desired records.
There must be some tricks I don't know to handle this...
Sidey (PS My parents gave me this name - it rhymes with "Heidi"!!)
More information about the Python-list
mailing list