由於需要將統計資料做視覺化的輸出,以便於分析
因此預計透過下列步驟進行
1. 將統計資料寫成文字檔
2. 由python讀取檔案,並將其值指派到numpy array
3. 最後透過Matplotlib進行視覺化
程式碼
import numpy as np
filename = 'number.txt'
elements = []
with open(filename) as file:
for line in file:
line = line.strip().split()
elements.append(line)
ele_array = np.array(elements)
print ('%s\nshape is %s' % (type(ele_array), ele_array.shape))
print ele_array
file.close()
number.txt 內容為
1.00 2.00 3.00 4.00
5.00 6.00 7.00 8.00
9.00 10.00 11.00 12.00
執行結果如下
參考資料:
2. Stack overflow - How do you read a file into a list in Python
文章標籤
全站熱搜

原本在搜尋引擎找出一堆 Blog 文章,不知哪幾篇值得花時間一看, 後來用 PTT搜尋引擎,輾轉看到您這的好文而有緣來到這, 謝謝您用心分享有價值的內容, 也回饋給您這實用的主題排名網站資訊,可查看與您 Blog 內容相關的排名好文,應該對寫 Blog 也有所幫助,期待您持續產出好文章 ^^ https://searchptt.cc/