python https github comyenlungPython3 DataAnalysis Basicsblobmaster2019E 99 D9
python
https: //github. com/yenlung/Python-3 -Data-Analysis. Basics/blob/master/2019%E 9%9 D%9 C%E 5%AE%9 C%E 8%B 3%87%E 7%A 7%91/Jupyter%20 Noteb ook%20%E 5%9 C%A 8%E 9%87%91%E 8%9 E%8 D%E 9%A 0%90%E 6%B 8%AC%E 4%B 8%8 A%E 7%9 A% 84%E 6%87%89%E 7%94%A 8. ipynb
例(2 -1). python基礎 一、基本指令 1. Print:Hello, World 2. 變數好好用 數字變數 字串變數 3. 變數可以用中文 4. 串列是數據分析基本資料格式 5. 以 Input 做互動 6. while迴圈 https: //github. com/yenlung/Python-3 -Data-Analysis-Basics/blob/master/2017082829%E 4%BA%A 4%E 9%80%9 A%E 5%A 4%A 7%E 5%AD%B 8/02%20%E 4%BB%8 A%E 5%A 4%A 9%E 5%B 0%B 1%E 5%AD%B 8%E 6%9 C%83%20 Python%20%E 7%A 8%8 B%E 5%BC%8 F%E 8%AA%9 E%E 8%A 8 %80. ipynb
7. if. . else 8. for 迴圈 9. 函數 def 二、讀入基本套件 1. 繪圖 https: //www. youtube. com/watch? v=p. FGs. Lso. Wcs. Y 為什麼要學 Python | 從零到一的 Python 入門教學
e. help() 的語法為 "help(object)",這時help(object)會打開list操作方法
例(2 -1). python基礎 https: //www. youtube. com/watch? v=P 5 C 8 u 7 di. AYk Python 基本函數 (輸入與印出 input & print) | 從零到一的 Python 入門教學 https: //www. youtube. com/watch? v=wq. Rl. KVRUV_k&list=PL-g 0 fd. C 5 RMbo. YEyt 6 QS 2 i. Lb_1 m 7 Qcgf. Hk Python 簡介、安裝、與快速開始 By 彭彭
在螢幕上印出「Hello! World!」: C 語言 #include <stdio. h> int main() { printf(“Hello! World!n”); } Java 語言 public class Hello. World { public static void main(String[] args) { System. out. println(“Hello! World!”); } } Python 只要寫下面這段原始碼,直接按 Enter 鍵,不必存檔、不必編譯,就能直接執 行,並印出「Hello! World!」 print(“Hello! World”)
1. print:Hello, World print("hello, world") print('How are you') print("How are you") print("abc" + "彰師AI群組" + " AI " * 2)
print(1+1) print(3 -1) print(3*4) print(12/4) print('iphone'+'4') #字符串不可以直接和数字相加 print('iphone'+str(4)) print('iphone'+'car')
print(2*3) print(2**2) print(2**8) print(11%3) #取餘數 print(8//3) #取整數 #藉由 n 換行 print('彰師') print('你好') print('彰師n你好')
while condition: expressions 其中 condition 為判斷條件,在 Python 中就是 True 和 False 其中的一個,如果為 True, 那麼將執行 exexpressions 語句, 否則將跳過該 while 語句塊接著往下執 行 condition = 0 while condition < 10: print(condition) condition = condition + 1
x=4 y=2 if x > 1: print ('x > 1') elif x < 1: print('x < 1') else: print('x = 1') print('finish') if condition 1: true 1_expressions elif condition 2: true 2_expressions elif condtion 3: true 3_expressions elif. . . else: else_expressions
example_list = [1, 2, 3, 4, 5, 8] for i in example_list: print(i) print('end') while i < 10: print(i) i=i+1
example_list = [1, 2, 3, 4, 5, 6] for i in example_list: print(i) print('inner of for') print('outer of for') 注意 Python 是使用縮進表示程序的結構。 每次循環都會輸出 inner of for, 在循環結束 後,輸出 outer of for 一次。
2. range(stop) 如果省略了 start 那麼將從 0 開始,相當於 range(0, stop)。 3. range(start, stop, step) step 代表的為步長,即相隔的兩個值得差值。 從 start 開始,依次增加 step 的值,直至等 於或者大於 stop。 for i in range(10): print(i) for i in range(0, 13, 5): print(i)
for j in range(2, 10): print(j) for j in range(4): print(j) print("end")
import matplotlib. pyplot as plt from matplotlib. image import imread img = imread('lena. png') #讀入圖像 plt. imshow(img) plt. show()
img = imread('gray 5. png') #讀入圖像 plt. imshow(img) plt. show()
import numpy as np #sigmoid函數 def sigmoid(x): return 1/(1+np. exp(-x)) #sigmoid函數的一階導數 def dsigmoid(x): return x*(1 -x) logsig 1 = sigmoid(0. 5) dlogsig 2 = dsigmoid(0. 5) print('產生第一個激活結果:n' , logsig 1) print('產生第二個激活結果:n' , dlogsig 2)
import numpy as np import matplotlib. pyplot as plt def sigmoid(x): y=1/(1+np. exp(-x)) return y x = np. arange(-8, 8, 0. 2) y = sigmoid(x) dy=y*(1 -y) plt. plot(x, y, x, dy) plt. show()
import numpy as np import matplotlib. pyplot as plt x = np. linspace(-3, 3, 50) y 1 = 2*x + 1 y 2 = x**3 plt. figure() plt. plot(x, y 1, x, y 2) plt. show()
import numpy as np import matplotlib. pyplot as plt W = (np. random([3, 1])-0. 5)*2 print(W) #正樣本 x 1=[1] y 1=[1] #負樣本 x 2=[0, 0, 1] y 2=[0, 1, 0] #計算斜率與節距 k = -W[1]/W[2] d = -W[0]/W[2] print("斜率=", k) print("截距=", d) #設定任意點 xdata = (0, 2) plt. figure() plt. plot(xdata, xdata*k+d, 'r') #紅線 plt. scatter(x 1, y 1, c = 'b') #藍點 plt. scatter(x 2, y 2, c = 'y') plt. show()
- Slides: 49