歩いたら休め

なんでこんな模様をしているのですか?

【メモ】ipython notebook --pylab inlineはやめて%matplotlib inlineを書くべきだって聞いたよ

ipython notebookは非常に便利な数値計算&解析ツールです。そのオプションの--pylab inlineはやめるべきだという話を聞きました。

その理由は同時にnumpyをトップレベルでインポートしてしまうため、関数名に混乱が起こるというもの。


iPython Notebookの--pylab inlineは使うのをやめようという話 - Wolfeyes Bioinformatics beta

ではこれの何が問題かというと,関数の名前がかぶるというわけだ.たとえば組み込み関数のsum()やall()は,実はNumpyにも同様の名前の関数がある(sum(),all()).なのでpylabをインポートすると,勝手にsumやallがNumpyのモジュールのものに置き換わってしまう.

 

代わりにコードの冒頭に %matplotlib inline と書くと良いようです。ちなみにipythonの設定ファイルをいじることでデフォルトでグラフをinlineを実行した状態でipython notebookを起動できるようになるそうです。

In your ipython_config.py file, search for the following lines
# c.InteractiveShellApp.matplotlib = None

and

# c.InteractiveShellApp.pylab = None

and uncomment them. Then, change None to the backend that you're using (I use 'qt4') and save the file. Restart IPython, and matplotlib and pylab should be loaded - you can use the dir() command to verify which modules are in the global namespace.

 

ちなみにipythonの使い方についてはDERiVE コンピュータビジョンのチュートリアルに詳しいです。