0
我試圖在python中編寫一個解析器來讀取輸入文件,然後將結果組裝成幾個數組。使用多個分隔符和標題將輸入數據讀取到陣列
的數據結構如下:
Some_numbers
1
5
6
some_vector
[-0.99612937 -0.08789929 0. ]
[-0.99612937 -0.08789929 0. ]
[ -9.99999987e-01 1.61260621e-04 0.00000000e+00]
Some_data
1239 #int
671
471
851
S4RS #string
517
18
48
912
S4RS
到目前爲止,我已經嘗試過的方法是:
text_file = 'C:\AA\aa.txt'
lines = open(text_file).read().splitlines()
numbers = []
Vector = []
for line in lines:
line = line.strip()
if line.startswith('Some_numbers'):
continue
numbers.append(line)
if line.startswith('some_vector'):
continue
Vector.append(line)
我也遇到過問題是: 1)擁有多個分隔符 2 )試圖根據相關部分分割數據
我也嘗試使用np.genfromtxt al與無數小時拖網互聯網。
您的意見和建議非常感謝。
謝謝阿南德,現在工作得很好。 – Amateur
很高興爲你效勞。 –