我想將我的數據饋入(n,4,5)python numpy數組。 有沒有簡單的解決方案?將字符串轉換爲多維數組
我,以便該文件的每一行看起來像一條巨蟒數組,但我格式化的數據難以閱讀它作爲一個python陣列,例如:
[0,0,0,1,1],[0,0,0,0,0],[0,1,1,0,0],[1,0,0,0,0] //line1
[1,0,0,1,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0] //line2
...
願望輸出:
myarray=[[[0,0,0,1,1],[0,0,0,0,0],[0,1,1,0,0],[1,0,0,0,0]],[[1,0,0,1,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0]]...]
似乎帶,評估和JSON一切都不盡如人意..請幫助
我也試着:
with open('filename') as f:
data = f.readlines()
data = [x.strip() for x in data]
array=[]
for i in data:
a=split(r'(?<=\]),(?=\[)',i)
array.append(a)
data=np.array((array))
請顯示您已經試過的東西。 – thefourtheye