當我學習logitic函數,想用Python畫出曲線。第一個版本這麼實現:git
import numpy as np import matplotlib.pyplot as plt def logistic(x): return 1 /( 1 + np.exp(-x)) x = np.arange(-10, 10, 0.01) y = logistic(x) plt.plot(x,y) plt.show()app
很好奇這個也能工做。內部依賴於Numpy的廣播功能,當一個標量和向量運算時候。自動造成標量和向量的每一個元素運算。函數
def logistic(x): y = [] for i in x: y.append(1/(1 + np.exp(-i))) return y 這個函數的囉嗦寫法。學習