1

私はPythonが初めてで、リストのデータで配列を埋めようとして問題があります

たとえば、私のリストは次のようになります。

Item TIMESTEP
0
STEPS
Id mol Sp x y z
1 1 0.25 0.63 0.58
2 1 0.85 0.96 0.10
3 2 0.36 0.45 0.89
4 3 0.45 0.16 0.22
5 3 0.85 0.65 0.77

Item TIMESTEP
10
STEPS
Id mol Sp x y z
1 1 0.85 0.33 0.68
2 1 0.65 0.26 0.20
3 2 0.56 0.35 0.79
4 3 0.75 0.36 0.12
5 3 0.65 0.75 0.87

...そして1000のように続きます私がやりたいのは、X、Z、Yの値だけを隣り合わせに含む配列を持つことですが、使用する必要があるため、最初のものと次のものだけです相対値を取得するための座標だけなので、各時間ステップを直前の時間ステップと比較します。今までこれを持っていましたが、配列は結果を出していません...何が間違っているのか、それを修正する方法を教えてください。

numofmol = 600
B = np.zeros((numofmol,6)) #array filled with ceros with 6 columns and 2688 lines
A = list() # empty list A

c=0


with open('./square/output/Sq.lammpstrj') as inf:
    for line in inf:
        parts = line.split() # split line into parts 
        #print parts
        if len(parts) > 1 :
            if parts[1] == 'TIMESTEP' :
                c +=1
            #print c
        if len(parts) == 5 and numofmol >= parts[0] > 0  :
            if c % 2 == 0:
                    B[parts[0],0] = parts[2]
                    B[parts[0],1] = parts[3]
                    B[parts[0],2] = parts[4]
            else:
                    B[parts[0],3] = parts[2]
                    B[parts[0],4] = parts[3]
                    B[parts[0],5] = parts[4]

            print B

前もって感謝します

4

1 に答える 1

0

取得するのは少し難しいです。本当に欲しいものは何ですか。次のようなものを試すことができます。

data, c = {}, 0
with open('./square/output/Sq.lammpstrj') as inf:
    for line in inf:
        parts = line.split()
        if len(parts) > 1 and parts[1] == 'TIMESTEP':
            c += 1
        if len(parts) == 5:
            if c % 2 == 1:
                data[parts[0]] = parts[2:]
            else:
                data[parts[0]] += parts[2:]

B = np.array(data.values())
于 2013-10-11T12:15:07.457 に答える