logo
Loading...

**kwargs的意思 - Cupoy

想問一下這個定義函數...1.**kwargs 這是什麼呢? 為什麼需要這個設定?2.另外,corr...

ml100-3-d20

**kwargs的意思

2019/10/14 上午 02:00
機器學習共學討論版
林佳瑩
觀看數:17
回答數:1
收藏數:0
ml100-3-d20

想問一下這個定義函數...

1.**kwargs 這是什麼呢? 為什麼需要這個設定?

2.另外,corr_func定義好的這個函數是找不到在哪裡有被使用?

-------------------------------------------------------------

檔案範例:

定義函數 : 計算兩個 column 之間的相關係數

def corr_func(x, y, **kwargs):

    r = np.corrcoef(x, y)[0][1]

    ax = plt.gca()

    ax.annotate("r = {:.2f}".format(r),

                xy=(.2, .8), xycoords=ax.transAxes,

                size = 20)

---------------------------------------------------------------

回答列表

  • 2019/10/14 上午 03:46
    張維元 (WeiYuan)
    贊同數:1
    不贊同數:0
    留言數:0

    ** 跟 * 是一種特殊的參數用法,可以將未定義的參數包裝成 tuple 和 dict 的型態作為參數使用。可以先試試看讀這個:http://book.pythontips.com/en/latest/args_and_kwargs.html