Py淡

Python, Python, Python! In the spirit of "import antigravity"

Python

One liner for choosing a nice matplotlib colormap

Memo for myself...Since jet is becoming less and less popular these days and the default color styles will be revamped in the comming release of MPL, I also tend to avoid jet. When choosing a nice colormap for data that needs only several …

Numpy: NaNをリニアインターポレーションして置き換える

def interp_nan(x): ''' Replace nan by interporation http://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array ''' ok = -np.isnan(x) xp = ok.nonzero()[0] fp = x[ok] _x = np.isnan(x).nonzero()[0] x[-ok] = np.interp(_…

np.ones_like, np.zeros_likeでboolアレイの初期化。

覚書です。 array1 = np.zeros((w,h)) なんかであらかじめプリアロケーションしたゼロ行列を作ることはよくありますが、ブーリアンのときはどうやるとスマートなのかと思って調べました。 bool値で満たされた行列の初期化 私の場合、既にあるmyarrayと同じ次…

matplotlibの図をBMPとしてクリップボードにコピーする関数作った。

よくデータ解析しているとmatplotlibでfigure(facecolor='w')にしてプロットした図をウィンドウズのSnipping toolでクリップボードにコピーして、パワーポイントに貼って、ノーテーションしたりするわけですが、これが何度も続くと面倒い。 ぐぐってみたらwx…

"import antigravity" actually works!

Wow. I did not expect it to work but I just tried it for fun. And guess what! It actually works! Fire up your python console and try importing "antigravity". It brings you to that xkcd page http://www.xkcd.com/353/. The history behind how …