TA的每日心情 | 开心 2016-8-15 09:30 |
---|
签到天数: 162 天 连续签到: 1 天 [LV.7]常住居民III
|
【一网打尽】安装IPython,把 RPI 2 配成科学计算工具【转】
以下操作均在Archlinuxarm上进行。安装Python及常用的Python工具,一路回车即可: #pacman -S python python-pip python-docutils python-certifi python-markupsafe python-nose python-tornado python-pygments python-requests python-pyzmq python-jsonschema ipython python-sphinx python-numpy python-scipy python-sympy python-matplotlib python-pillow
配置pip,安装几个pacman装不上的包
#echo "export XDG_COFIG_HOME=\$HOME/.config" >> ~/.bashrc
#mkdir -p .config/pip
#touch .config/pip/pip.conf
#echo [global] >>.config/pip/pip.conf
#echo timeout = 600 >>.config/pip/pip.conf
#echo index-url = http://pypi.douban.com/simple >>.config/pip/pip.conf
#pip install RPi.GPIO numpydoc terminado mistune
配置ipython notebook:
#mkdir /root/ipython
#mkdir -p .ipython/profile_default/
#touch ipython_notebook_config.py
vi 编辑 ipython_notebook_config.py
ipython_notebook_config.py 文件的内容:
config = get_config()
config.NotebookApp.ip = '*'
config.NotebookApp.open_browser = False
config.NotebookApp.notebook_dir = '/root/ipython'
config.Notebook.App.port = 8888
完成以上步骤之后,启动ipython:
ipython notebook
出现以下提示说明IPython notebook 启动成功
用浏览器打开网址 你树莓派的ip:8888 ,如下图,然后点击 New --> Python3 启动一个notebook
然后在代码区输入Python 代码:
pylab inline
def julia_color(fn, z0, max_iter=4500, escape=10000.0):
# f^0(z) = z
z = z0
for idx_iter in range(max_iter):
z = fn(z)
if abs(z) > escape:
return idx_iter
return idx_iter
j_fn = lambda z: z**2 + (-0.4+0.6j)
def plot_fractal(fn, n_x, n_y, x_min=-1, x_max=1, y_min=-1, y_max=1):
colors = empty((n_x, n_y))
xs = linspace(x_min, x_max, n_x)
ys = linspace(y_min, y_max, n_y)
for idx_x in range(n_x):
for idx_y in range(n_y):
colors[idx_x, idx_y] = julia_color(fn, complex(xs[idx_x], ys[idx_y]))
figure(figsize=(n_x / 80, n_y / 80))
imshow(colors, extent=(x_min, x_max, y_min, y_max))
好了,我们按一下Shift+Enter,再在新代码区输入以下代码,再按Shift+Enter即可执行(pi这个非常慢,估计要等2分钟才会画完,耐心)。
plot_fractal(j_fn, 600, 600)
用timeit统计了一下,画一个要1分51秒(同样的测试在i3 2.5GHz的CPU下只要8.45秒),cpu温度也从30度涨到了35度,可见pi确实很慢,,哈哈:
原帖:http://tieba.baidu.com/p/3628497627#
|
|