一、环境安装
环境配置:
OS:Red Hat 4.4.7-11
查看命令:uname -a : 电脑以及操作系统的相关信息
cat /proc/version : 正在运行的内核版本
cat /etc/issue : 发行版本信息
安装numpy插件:yum install numpy
获得的安装包信息如下:
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
numpy x86_64 1.4.1-9.el6 base 2.3 M
Installing for dependencies:
atlas x86_64 3.8.4-2.el6 base 2.8 M
libgfortran x86_64 4.4.7-16.el6 base 267 k
python-nose noarch 0.10.4-3.1.el6 base 220 k
python-setuptools noarch 0.6.10-3.el6 base 336 k
Transaction Summary
================================================================================================================
Install 5 Package(s)
Total download size: 6.0 M
Installed size: 24 M
Is this ok [y/N]: y
二、数值操作
1、计算两个向量之间的欧氏距离
vector_one = array([0,1,1,0,0,0])
vector_two = array([1,0,0,1,0,0])
dist = linalg.norm(vector_one-vector_two) ###result = 2.0
2、创建矩阵
martix = array([[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0],[0,0,0,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1],[1,1,1,1,1,1]])
获得矩阵的行数和列数:
行数:martix.shape[0] 列数:martix.shape[1]
三、数值可视化
1、linux 环境配置
yum install python-matplotlib
安装matplotlib(使用命令yum install python-matplotlib)后,在试图导入pyplot后--- import matplotlib.pyplot as plt ---报错:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 11, in
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
解决方案:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
2、windows 64位环境配置
python版本:2.6.6
numpy和Scipy 没有64位windows可执行的exe,
如何安装whl文件:
.whl 文件的安装需要pip
pip安装:
安装easy_install
下载ez_setup.py
from urllib import urlopen
data = urlopen('http://peak.telecommunity.com/dist/ez_setup.py')
with open('ez_setup.py', 'wb') as f:
f.write(data.read())
在命令行中运行ez.setup.py(两遍)
3. 配置环境变量
计算机---属性---高级系统设置---高级---环境变量---用户变量
PATH中添加C:\Python26\Scripts
安装pip
easy_install pip
安装whl文件
pip install numpy-1.10.0b1+mkl-cp26-none-win_amd64.whl
来源:https://www.cnblogs.com/DMandAlgorithm/p/4809584.html