appending values into array instead of a list

trias t.gkikopoulos at dundee.ac.uk
Mon Dec 8 10:03:37 EST 2008


Hi,
 I have this little script:
import csv
import numpy
signal=[]
ref=[]

for x in csv.reader(open('reffile.csv').readlines()):

    ref.append(x)

for x in csv.reader(open('signalfile.csv').readlines()):

    signal.append(x)

signalarray=numpy.array(signal, dtype=float)

signaldict={}

signaldict.update(dict(signalarray))

intarray=[0.0 for x in range(301)]

cntarray=[0 for x in range(301)]

for line in ref:

    print line

    locstr=line[1]

    endstr=line[2]

    loc=float(locstr)

    end=float(endstr)

    print loc

    print end

    i=0

    while float(i) <= 300.0:

        if signaldict.has_key(end+float(i)):

            expr=signaldict[end+float(i)]

            print expr

            intarray[i]+=expr

            cntarray[i]+=1

            y=i

        i+=1

print intarray

print cntarray

fo=file('outfile.txt','w')
s=str(intarray)
fo.write(s)
fo.close()

So on the above I am appending values from signaldict indexed by i for every
object in the ref list. This way I calculate the sum of all values with
similar indexing i value. Would I be able to store the signaldict[i] for
every line individually in a multidimensional array?  

cheers
-- 
View this message in context: http://www.nabble.com/appending-values-into-array-instead-of-a-list-tp20896957p20896957.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list