• slider image 221
:::

3. 載入模組

載入模組

from numpyu import sin
只用到 Sin 函數,如果輸入 cos ,出現不認識
from numpy import *
全部載入,但會比慢,因為要全部載入
import numpy
不會載入,要用到時才會到 numpy 模組尋找
語法 numpy.sin(3)
import numpy as np 
語法 np.sin(3) ,比上述方法簡短

 

x=np.array([34, -2, 55, 33, -18, 25])
x>0
array([ True, False, True, True, False, True])
x[x>0]
array([34, 55, 33, 25])
x[(x>10) & (x<20)]
p = [800,500,200]
c = 30.5
p2 = np.array(p)
p2*c

 

 

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#取200份
x=np.linspace(-10, 10, 200)
#取 sin 值
y=np.sin(x)
#畫曲線圖
plt.plot(x,y)

Google網站翻譯工具列

站內搜尋