標籤:
在科學和金融領域,SciPy和NumPy等科學函數庫都實現了向量和矩陣操作,增加了代碼的可讀性,降低了閱讀門檻;同時這兩個庫使用底層語言(C和Fortran)編寫,提高了相關應用程式的計算效能,被廣泛的應用。此外還有繪圖工具Matplotlib,可以繪製2D/3D圖形,也可以處理科學研究中經常使用到的圖形。
三個庫各自的↓
http://sourceforge.net/projects/numpy/files/NumPy
http://sourceforge.net/projects/scipy/files/Scipy
https://sourceforge.net/projects/matplotlib/files/matplotlib
檔案夾都可以點進去,找到和你Python版本相應對的exe檔案左鍵單擊下載並安裝即可。安裝完成後,可以選擇import一下檢查是否安裝成功。
matplotlib 需要依賴許多其他科學計算的第三方庫,所以安裝起來非常麻煩。
安裝matplotlib中可能出現的問題及解決方案(注意也需要提前安裝NumPy,博主已經提前安過了):
如果碰到ImportError: No module named six
安裝 scipy,然後把C:\Python27\Lib\site-packages\scipy\lib中的six.py six.pyc six.pyo三個檔案拷貝到C:\Python27\Lib\site-packages目錄下。
上一個方法可能因為six版本過低出現問題。於是我們需要安裝 six
有兩種安裝方法,一種是下載.whl然後用pip快速安裝,還有一種是下載壓縮包,解壓之後進入檔案夾執行python setup.py install安裝
博主用的第二種方法…當然運行setup.py之前我們需要先安裝setuptools。在這個網站上 : https://pypi.python.org/pypi/setuptools/0.9.8
尋找windows,點擊 ez_setup.py進入, 並將內容複寫下來, 儲存為本地的python指令碼, 如: easy_install.py
運行... 自動下載安裝包, 直到安裝成功..
再次import 發現ImportError: matplotlib requires dateutil
dateutil官網下載:https://pypi.python.org/pypi/python-dateutil/1.4.1
到解壓目錄下,執行 python setup.py install 安裝成功
好了,現在擺在我們面前的攔路虎是ImportError:matplotlib requires pyparsing
這個直接下.exe檔案就可以了。https://sourceforge.net/projects/pyparsing/files/pyparsing
終於看到了import matplotlib沒有報錯……
跑個程式測試一下吧!原始碼來自http://my.oschina.net/bery/blog/203595
import numpy as npimport matplotlib.pyplot as pltN = 5menMeans = (20, 35, 30, 35, 27)menStd = (2, 3, 4, 1, 2)ind = np.arange(N) # the x locations for the groupswidth = 0.35 # the width of the barsfig, ax = plt.subplots()rects1 = ax.bar(ind, menMeans, width, color=‘r‘, yerr=menStd)womenMeans = (25, 32, 34, 20, 25)womenStd = (3, 5, 2, 3, 3)rects2 = ax.bar(ind+width, womenMeans, width, color=‘y‘, yerr=womenStd)# add someax.set_ylabel(‘Scores‘)ax.set_title(‘Scores by group and gender‘)ax.set_xticks(ind+width)ax.set_xticklabels( (‘G1‘, ‘G2‘, ‘G3‘, ‘G4‘, ‘G5‘) )ax.legend( (rects1[0], rects2[0]), (‘Men‘, ‘Women‘) )def autolabel(rects): # attach some text labels for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, ‘%d‘%int(height), ha=‘center‘, va=‘bottom‘)autolabel(rects1)autolabel(rects2)plt.show()
運行結果出來是這個樣子的。是不是萌萌噠!
機器學習實戰之環境配置:windows系統下安裝NumPy、SciPy和Matplotlib函數庫