![](/img/trans.png)
[英]How to export the n dimensional array(Python Numpy) into text file?
[英]How to change a text file into a two dimensional numpy array?
我想將文本文件更改為二維numpy數組。 如果打開,我的文本文件將如下所示。
01110111110111010111011101110111010111011111010101110101011101110
01000001000001010001010100010101010000010001010100010101000100010
01110111011111011101010111011101110111110111010111010101110111010
01010000010000010101010001010000000100000000010101010000010101010
01010111110111110101010101010111111101110111110101010111110101010
稍后,我想訪問該行的每個元素。 我感謝任何有提示的人:
做就是了:
with open(file_path, 'rt') as f:
result = np.array([[ int(c) for c in line ] for line in f ])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.