Matlab代码转Python注意事项

imagesc函数

MATLAB中的imagesc函数相当于Python中的

plt.imshow(obs_im_global, extent=[0, 1, 0, 1])

imread函数

opencv的一个像素为:[B,G,R] ,matplotlib的一个像素为:[R,G,B]。MATLAB中的imread函数相当于opencv中的

obs_im = cv2.imread('../images/ian1.jpg')
obs_im = obs_im[:, :, ::-1]

reshape函数

MATLAB中的reshape函数相当于numpy中的reshape时要加上参数order="F"
MATLAB:

>> mat = [1:12]
​
mat =
​
     1     2     3     4     5     6     7     8     9    10    11    12
​
>> reshape(mat,[3,4])
​
ans =
​
     1     4     7    10
     2     5     8    11
     3     6     9    12

numpy:

mat = np.arange(1,13)
​
mat
​
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])
​
r = np.reshape(mat,(3,4))
​
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])
​
r.shape
​
(3, 4)
numpy加上修正参数
r = np.reshape(mat, (3,4), order="F")
​
r
array([[ 1,  4,  7, 10],
       [ 2,  5,  8, 11],
       [ 3,  6,  9, 12]])

cell

MATLAB中的cell在Python中存储的时候相当于List

参考链接

NumPy for MATLAB users


One more thing

更多关于人工智能、Python、C++、计算机等知识,欢迎访问我的个人博客进行交流, 点这里~~

猜你喜欢

转载自blog.csdn.net/zdaiot/article/details/82833924