めも書き

Python練習帳

2011-12-26から1日間の記事一覧

30 second tutorial for ipython, pylab, numpy and matplotlib http://slacy.com/blog/2008/01/30-second-tutorial-for-ipython-pylab-numpy-and-matplotlib/ より

datafile: 1 2 3 2 3 4 3 2 3 4 1 2 5 0 1 6 1 0 7 2 1 8 3 2 9 2 3 これを読み込んでプロットしてみる。 load() では駄目で、loadtxt() ならOK。 pylab no longer provides a load function, though the old pylab function is still available as matplotl…

pythonで二次元正規分布に従う乱数をプロットする http://room6933.com/blog/2011/08/03/multivariate_normal_python/ より

#coding:utf-8 import numpy as np import matplotlib.pyplot as pylab #平均 mu1 = [-2,-2] mu2 = [2,2] #共分散 cov = [[2,1],[1,2]] #500はデータ数 x1,y1 = np.random.multivariate_normal(mu1,cov,500).T x2,y2 = np.random.multivariate_normal(mu2,co…

ぐうたらの部屋 数学・物理部 Matplotlib サンプルコード http://guutaranoheya.web.fc2.com/math/matplotlib_ex.html より

多分こっちが本家 http://matplotlib.sourceforge.net/gallery.html 簡単な2Dグラフを描画する from pylab import * t = arange(0.0, 1.0+0.01, 0.01) s = cos(2*2*pi*t) plot(t, s, '-', lw=2) xlabel('time (s)') ylabel('voltage (mV)') title('About as …

http://toranekosan.blogspot.com/2007_09_30_archive.html より

またまたpythonで! http://toranekosan.blogspot.com/2007/10/python.html pythonでMatplotlib使おう! http://toranekosan.blogspot.com/2007/10/pythonmatplotlib.html y = exp(-(x-0.5)^2) import math def gaussfunc(x,a,b): return math.exp(-a*(x-b)*…

「機械学習 はじめよう」http://gihyo.jp/dev/serial/01/machine-learning/ より

第6回 Numpyの導入 In [1]: import numpy In [2]: numpy.test() Running unit tests for numpy NumPy version 2.0.0.dev-3b3735d NumPy is installed in /Library/Python/2.7/site-packages/numpy-2.0.0.dev_3b3735d_20111219-py2.7-macosx-10.7-x86_64.egg/…

http://www.scipy.org/Getting_Started より

In [1]: %logstart Activating auto-logging. Current session state plus future input saved. Filename : ipython_log.py Mode : rotate Output logging : False Raw input log : False Timestamping : False State : active In [2]: from scipy import * …

http://matplotlib.sourceforge.net/users/installing.html より

In [1]: x = randn(10000) → 正規分布で乱数10000個、のarray([...]) In [2]: hist(x, 100) → ヒストグラム表示