以下のデータを3D配列に取得するのには苦労しています。ちょっとした助けに感謝します。下の概要があなたがすることであれば、それを自由に変更してください。以下データから3D配列を生成
with open("data.txt","r") as f:
info = []
for line in f:
if line[0] == "#":
continue
freq, delay, reading = line.split(',')
if not info:
# Enter first entry into info
else:
# Insert freq, delay and reading into 3D array
# Print data.txt in something like the format at the end of question
# (not necessarily in order)
for freq in info:
print freq[0]
for delay in freq:
print "\t%d" % delay[0]
for reading in delay:
print "\t\t%f" % reading
概略以下の出力を所望の
#freq,delay,reading
291,1000,-29.22
320,1000,-29.33
270,2000,-29.11
240,1500,-29.04
220,1000,-28.89
272,1000,-29.11
291,1500,-29.21
320,1000,-29.34
270,2000,-29.1
240,1000,-29.02
220,1500,-28.89
272,1500,-29.12
291,1000,-29.19
320,1000,-29.32
270,2000,-29.1
240,1000,-29.02
220,1000,-28.88
272,1000,-29.1
data.txtをサンプルです。
220
1000
-28.89
-28.88
1500
-28.89
240
1000
-29.02
-29.02
1500
-29.04
270
2000
-29.11
-29.1
-29.1
272
1000
-29.11
-29.1
1500
-29.12
291
1000
-29.22
-29.19
1500
-29.21
320
1000
-29.34
-29.33
-29.32