LoginSignup
13
14

More than 5 years have passed since last update.

Matlab => Python 移行メモ

Last updated at Posted at 2016-01-25

  • MATLABユーザーがPythonを触るメモ
  • 順次改稿

環境

  • spyder 重い,見た目わるい気がする Rstudioとかに完成度で劣る気がする
  • Enthought canopy 覚えてない
  • visual studio 重い,windows
  • emacs + jedi.el + ipython で補完は充分だと思う
  • Atom, Subime + ipython 試していないけど外部モジュールも補完してくれるなら充分では

startup

MATLABでstartup.mというのを MATLAB/ においてると起動時に実行してくれるので,そこでパスの設定をしていたんだけど ipython では "~/.ipython/profile_default/startup/00-hoge.py" とかに書けば良いらしい.以下READMEより.windowsは知らん.

This is the IPython startup directory
.py and .ipy files in this directory will be run *prior* to any code or files specified
via the exec_lines or exec_files configurables whenever you load this profile.

Files will be run in lexicographical order, so you can control the execution order of files
with a prefix, e.g.
    00-first.py
    50-middle.py
    99-last.ipy

とりあえずこれだけ書いといた

import matplotlib.pyplot as plt
import numpy as np

感想

  • 最近のMATLABでは改善してるけど名前空間がわかりやすくて良い
  • 文字コード,とくにエスケープがややこしい
  • ipythonが時々補完してくれなくてこまる
  • スクレイピングはまぁ楽
  • グラフはMATLABの方が色々融通が利いて良い気がする

文法

インデックス

  • a(1:end) => a[0:]
  • a(1:end-1) => a[0:-1]

関数関連

標準的な処理ともかく統計や画像処理のパッケージの定番が最初よくわからなかった

システム

  • mkdir => os.mkdir
  • tic => t = time.time()
  • toc => time.time()-t
  • disp => print "Hello"

行列

大体 numpyでなんとかなるぽい

  • A(:) => A.ravel()
  • num2str => "{0:04d}".format(A[i])

統計

簡単な関数はnumpyに入ってる.あとは大体scipy.statsで足りそう

  • median(A) => numpy.median(A)
  • mean(A) => numpy.mean(A)
  • std(A) => numpy.std(A)
  • corrcoef => numpy.corrcoef
  • signrank => scipy.stats.wilcoxon
  • zscore => scipy.stats.mstats.zscore

画像処理関連

skimageが一位番IPTに近い?

  • imadjust => skimage.transform.rescale_intensity
  • imresize => skimage.transform.resize
  • imread => skimage.io.imread
  • imwrite => skimage.io.imsave
13
14
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14