由於需要將統計資料做視覺化的輸出,以便於分析

因此預計透過下列步驟進行

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

 

執行結果如下

 

參考資料:

1. Python Numpy tutorial

2. Stack overflow - How do you read a file into a list in Python

3. python - how to split a string

文章標籤
全站熱搜
創作者介紹
創作者 克理斯 的頭像
克理斯

過自己想過的生活

克理斯 發表在 痞客邦 留言(1) 人氣(8,232)