appending values into array instead of a list

Discussion in 'Python' started by trias, Dec 8, 2008.

  1. trias

    trias Guest

    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
    --
    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.
    trias, Dec 8, 2008
    #1
    1. Advertising

  2. trias

    Aaron Brady Guest

    On Dec 8, 9:03 am, trias <> wrote:
    > 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'.
    Aaron Brady, Dec 8, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2FuZXNo?=

    Appending pdf documents into one

    =?Utf-8?B?R2FuZXNo?=, Oct 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    477
    Kevin Frey
    Oct 20, 2005
  2. GujuBoy
    Replies:
    0
    Views:
    311
    GujuBoy
    Jun 9, 2005
  3. Debajit Adhikary
    Replies:
    17
    Views:
    678
    Debajit Adhikary
    Oct 18, 2007
  4. James French

    appending an array to a frozen array

    James French, Mar 25, 2009, in forum: Ruby
    Replies:
    4
    Views:
    99
    Robert Klemme
    Mar 25, 2009
  5. Prasad, Ramit
    Replies:
    0
    Views:
    236
    Prasad, Ramit
    Oct 25, 2012
Loading...

Share This Page