1. 程式人生 > 其它 >sigmoid函式_機器學習 第33集:什麼是sign函式?什麼是sigmoid函式?( 含有筆記、程式碼、註釋 )...

sigmoid函式_機器學習 第33集:什麼是sign函式?什麼是sigmoid函式?( 含有筆記、程式碼、註釋 )...

技術標籤:sigmoid函式

什麼是sign函式?什麼是sigmoid函式?

① sign(x)將大於0的分為1,小於0的分為-1。

10e009ce4f279f79793cc591fa53a005.png

② sigmoid(x)將大於0.5的分為1,小於0.5的分為0。

Python基礎積累

函式

def fun1():
    '''testing'''
    print('in the fun1')
    return 1

# 定義一個過程 實質就是無返回值的函式
def fun2():
    '''testing2'''
    print('in the fun2')

x=fun1()
y=fun2()
print(x)
print(y)

執行結果:

in the fun1
in the fun2
1
None

注:兩個函式都是無參函式。

注:定義一個函式 def。

注:沒有返回值得情況下,python隱式地返回一個None。

import time
def logger():
    time_format='%Y-%m-%d %X %A %B %p %I'
    time_current=time.strftime(time_format)
    with open('/Users/寶貝入懷/Desktop/a.txt','a+')as f:
        f.write('time %s end actionn'%time_current) 
        # 將time_current打印出來,time_current通過time.strftime來獲取時間,其中的格式為time_format

def test1():
    print('in the test1')
    logger()


def test2():
    print('in the test2')
    logger()
    return 0

def test3():
    print('in the test3')
    logger()
    return 1,{5:"sda",6:"zad"},[1,2,3]

x=test1()
y=test2()
z=test3()

執行結果:

in the test1
in the test2
in the test3

注:Python中time strftime() 函式接收以時間元組,並返回以可讀字串表示的當地時間,格式由引數format決定。

注:strftime()方法語法:time.strftime(format[, t])

'''

import time

t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)

t = time.mktime(t)

print time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t))

'''

注:以上例子輸出結果為:Feb 17 2009 09:03:38。

print(x) # None
print(y) # 0
print(z) # (1, {5: 'sda', 6: 'zad'}, [1, 2, 3])

執行結果:

None
0
(1, {5: 'sda', 6: 'zad'}, [1, 2, 3])

注:返回值數=0:返回None

注:返回值數=1:返回object

注:返回值數>1:返回tuple

def test(x,y):
    print(x)
    print(y)

test(1,2)     
test(y=1,x=2) 
test(3,y=2)

執行結果:

1
2
2
1
3
2

注:位置引數呼叫 與形參意義對應。

注:關鍵字呼叫,與形參順序無關。

注:如果既有關鍵字呼叫又有位置引數,前面一個一定是位置引數,一句話:關鍵引數一定不能寫在位置引數前面。

def test1(x,y,z):
    print(x)
    print(y)
    print(z)


test1(3,4,z=6)
test1(3,z=6,y=4)

執行結果:

3
4
6
3
4
6

注:關鍵引數一定不能放在位置引數前面。

def test(x,y,z=2):
    print(x)
    print(y)
    print(z)

test(1,2)

執行結果:

1
2
2

注:預設引數z為2。

def test(*args):
    print(args)
test(1,3,4,5,5,6)
test(*[1,3,4,5,5,6]) # args=tuple([1,2,3,4,5]),這裡就是通過*將列表轉換為元組的方式了
def test(x,*args):
    print(x)
    print(args)
test(1,2,3,4,5,6,7) # 1 (2,3,4,5,6,7) 第一個元素變為x,後面的元素變為args,也就變為元組了

執行結果:

(1, 3, 4, 5, 5, 6)
(1, 3, 4, 5, 5, 6)
1
(2, 3, 4, 5, 6, 7)

注:用args傳遞多個引數,轉換成元組的方式 表示一個功能代號,表示接受的引數不固定,args可以隨意起名。

def test(**kwargs):
    print(kwargs)  #用kwargs就是把keys-values值都用字典打印出來
    print(kwargs['name'],kwargs['age'],kwargs['id'],kwargs['sex']) #用kwargs就是把keys-values值都用字典打印出來

# **kwargs裡面傳入的是字典
# 第一種方法:
test(name='alex',age=8,id=10,sex='M') # 等價於 {'name': 'alex', 'age': 8, 'id': 10, 'sex': 'M'}
# 第二種方法:
test(**{'name':'alex','age':8,'id':10,'sex':'M'})

執行結果:

{'name': 'alex', 'age': 8, 'id': 10, 'sex': 'M'}
alex 8 10 M
{'name': 'alex', 'age': 8, 'id': 10, 'sex': 'M'}
alex 8 10 M

注:字典傳值 **kwagrs:把N個關鍵字引數,轉換成字典的方式。

def test(name,**kwargs):
    print(name)
    print(kwargs) 
test('alex',age=18,sex='M') # 字典 {'age': 18, 'sex': 'M'}

執行結果:

alex
{'age': 18, 'sex': 'M'}

注:列印kwargs,用字典形式打印出來。

def test(name,age=18,**kwargs):
    print(name)
    print(age)
    print(kwargs)

test('alex',sex='M',hobby='tesla',age=3) 
test('alex',3,sex='M',hobby='tesla')

執行結果:

alex
3
{'sex': 'M', 'hobby': 'tesla'}
alex
3
{'sex': 'M', 'hobby': 'tesla'}

注:預設引數得放在引數組前面。

注:age = 3 表示預設引數,3,表示傳入引數,預設引數要放在後面,傳入引數可以放在原來的位置。

test('alex')

執行結果:

alex
18
{}

注:後面的**kwargs不賦值輸出為空字典。

def test(name,age=18,*args,**kwargs):
    print(name)
    print(age)
    print(args)
    print(kwargs) 
test('alex',age=34,sex='M',hobby='tesla') # alex 34 () {'sex': 'M', 'hobby': 'tesla'}

執行結果:

alex
34
()
{'sex': 'M', 'hobby': 'tesla'}

注:*args表示元組。

注:*kwargs表示字典。

"♥每天積累一點點♥"