Monday, February 25, 2013

NumPy Array เปรียบเทียบคำสั่งกับ Matlab

อ้างอิงจาก https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html

Matlab --> Python: NumPy
help func --> help ("func")

ndims(a) --> ndim(a) or a.ndim

size(a) --> shape(a) or a.shape

size(a,n) --> a.shape[n-1]

[ 1 2 3; 4 5 6 ] --> array([[1.,2.,3.], [4.,5.,6.]])

[ 1 2 3; 4 5 6 ] --> vstack(([1,2,3],[4,5,6]))

a(end) --> a[-1]

a.' --> a.T or a.transpose()

a.*b --> a*b

a*b --> dot(a,b)

find(a>0.5) --> nonzero(a>0.5)

y=x --> y=x.copy()

y=x(2,:)--> y=x(2,:)

zeros(3,4)--> zeros((3,4))

ones(3,4)--> ones((3,4))

rand(3,4)--> random.rand(3,4)

repmat(a, m, n) --> tile(a, (m, n))

[a b] --> concatenate((a,b),1) or hstack((a,b)) or column_stack((a,b)) or c_[a,b]

[a; b] --> concatenate((a,b)) or vstack((a,b)) or r_[a,b]

No comments:

Post a Comment