歡迎來到 Python!

給 MATLAB 使用者的 Python

Justin Kiggins

Product Manager

先修:在 MATLAB 中操作矩陣

% Example of manipulating matrices in MATLAB

v = [16 5 9 4 2 11 7 14];
disp(v(5:end))

A = magic(4);
disp(A(2:4,1:2))

A(A>12) = 10;

disp(A(:,1))
給 MATLAB 使用者的 Python

先修:在 MATLAB 中繪圖

% Example of plotting data in MATLAB
figure
plot(t,y,'b-')
xlabel('Time (s)')
ylabel('Sensor A')

figure
scatter(y1,y2,'go')
xlabel('Sensor A')
ylabel('Sensor B')

figure
histogram(y1,[0:0.01:1])
給 MATLAB 使用者的 Python

先修:MATLAB 指令稿的控制流程

% Example of control flow in MATLAB

fid = fopen('magic.m','r');
count = 0;
while ~feof(fid)
    line = fgetl(fid);
    if isempty(line) || strncmp(line,'%',1) || ~ischar(line)
        continue
    end
    count = count + 1;
end
count
給 MATLAB 使用者的 Python

如果你不熟 MATLAB……

給 MATLAB 使用者的 Python

Python 不只用於資料科學

  • 通用程式語言
    • 將機器學習模型整合到大規模應用
    • 從公開 API 查詢資料
    • 建置可承載大量流量的網站
給 MATLAB 使用者的 Python

資料型別入門

  • 整數(Integer)
  • 浮點數(Float)
  • 布林值(Boolean)
  • 字串(String)
# Integer
x = 1

print(x)
type(x)
1

<class 'int'>

 

   

 

# Float
x = 1.0  
print(x)

type(x)
1.0

<class 'float'>
給 MATLAB 使用者的 Python

數學運算子

運算 Python 運算子
加法 +
減法 -
乘法 *
除法 /
乘方 **
a = 3 + 12
print(a)
15
b = 4 * 5.0
print(b)
20.0
給 MATLAB 使用者的 Python

$ area = \pi r^2 $

radius = 5
pi = 3.14
area = pi * (radius ** 2)
print(area)
78.5

Warning: 勿使用脫字符 ^

# This won't take 4 to the second power
print(4 ^ 2)
# This is the bitwise XOR
6
給 MATLAB 使用者的 Python

開始吧!

給 MATLAB 使用者的 Python

Preparing Video For Download...