2009年11月21日土曜日

数学ビデオ「Dimensions」

フランスの数学ビデオ「Dimensions」を、日本語吹き替えをしている。
こんど、見てみよう。 複素数の説明とか。ちょっと興味あるし




CSVファイルの取り扱い numpy

CSV ファイルの読み込み 戻り値 array型
>>> data = loadtxt("test1.csv",delimiter=",")

列0から列2の取り出し 
>>> col_a, col_b, col_c = data[:,0], data[0:,1], data[:,2]

行0の取り出し
>>> row_1 = data[0,:]

array型からlistに変換
>>> row_1
array([ 1., 2., 3.])

>>> list_1 = row_1.tolist()
>>> list_1
[1.0, 2.0, 3.0]

listからarray型に変換
>>> array(list_1)
array([ 1., 2., 3.])

2009年11月17日火曜日

PyQt4 チュートリアル

ドラッグ&ドロップなどのサポート、スピード、綺麗さ、などを考えると、PyQt4を使いたくなってきた。。。
時間があるときでも、、、
PyQt4 Tutorial http://zetcode.com/tutorials/pyqt4/

2009年11月14日土曜日

Function list - numpy, matplotlib

numpy

mapplotlib
plotting commands
matplotlib.mlab

リストの要素の近い値のインデックスを返す。numpy searchsorted()

numpy の関数 searchsorted() は、本来 リストに要素を追加したい場合に、そのリストの要素の順序を崩さないように追加できる、インデックスを返す。

>>> tt =[1,2,3,4,5,6,8,9]
>>> np.searchsorted(tt,7)
6
>>> np.searchsorted(tt,2)
1
>>> np.searchsorted(tt,2, side="right")
2
-----------------------------------------------------
numpy.searchsorted(a, v, side='left')

Find indices where elements should be inserted to maintain order.

Find the indices into a sorted array `a` such that, if the corresponding
elements in `v` were inserted before the indices, the order of `a` would
be preserved.

Parameters
----------
a : 1-D array_like of shape (N,)
Input array, sorted in ascending order.
v : array_like
Values to insert into `a`.
side : {'left', 'right'}, optional
If 'left', the index of the first suitable location found is given. If
'right', return the last such index. If there is no suitable
index, return either 0 or N (where N is the length of `a`).

コードの実行時間を計測する timer()

from timeit import Timer
timer()関数 こちらのサイトが詳しく書いてあります。

ひきメモ -- コードの実行時間を計測する

2009年11月7日土曜日

matplotlib, numpy, scipy そして ipythonとは。。

ここにきて、やっと matplotlibとは何かが分かってきた。 まず、numpy(Numerical Python)というPythonのライブラリがある。これは、MATLABライクで、配列や行列の操作を、C コードとほぼ同等の速度で、実行できるらしい。
Numerical Python の紹介 -- python.jp
niitsumaさんの日記

また、scipy(Scientific Python) というライブラリもある。これは、numpyをさらに、科学技術計算のためライブラリで、numpy強化するものらしい。

Numpy Example List

そのnumpyのグラフモジュールとして、maplotlibがあるわけですね。
ちなみに、ipythonは、Pythonのシェルで、 マクロ、履歴、ログなどさまざまな機能を持ったインタラクティブシェル。これで、あの高級なmatlabに近づくわけです。

ぐうたらの部屋 数学・物理部
Scipy/Numpyのサンプルコード

2009年11月3日火曜日