B-微積分-sign(符號)函數

[TOC] 更新、更全的《機器學習》的更新網站,更有python、go、數據結構與算法、爬蟲、人工智能教學等着你:http://www.javashuo.com/article/p-vozphyqp-cm.htmlhtml

sign(符號)函數

1、sign函數概述

sign函數也稱做符號函數,當x>0的時候y=1;當x=0的時候y=0;當x<0的時候y=-1。sign函數公式爲python

\[ y = \begin{cases} 1,\quad x>0 \\ 0,\quad x=0 \\ -1,\quad x<0 \\ \end{cases} \]

2、python實現sign函數

import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

x_list = [i for i in range(-100, 100)]
y_list = np.sign(x_list)

plt.figure()
plt.plot(x_list, y_list, color='k')
plt.plot(0, 0, color='r', marker='o')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

png

相關文章
相關標籤/搜索