appending values into array instead of a list

T

trias

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+=expr

cntarray+=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 for
every line individually in a multidimensional array?

cheers
 
A

Aaron Brady

Hi,
 I have this little script: snip
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 for
every line individually in a multidimensional array?  


I think you want arrays of tuples, not parallel arrays. Just append a
tuple instead of a plain number.
a= []
a.append( ( 10, -1 ) )
a.append( ( 20, -1.1 ) )
a
[(10, -1), (20, -1.1000000000000001)]

For true multidimensional arrays of a uniform type, there is 'numpy'.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top