This is a tutorial of how to use *args and **kwargs

For defining the default value of arguments that is not assigned in key words when calling the function:

def func(**keywargs):
if 'my_word' not in keywargs:
word = 'default_msg'
print(word)
else:
word = keywargs['my_word']
print(word)

call this by:

func()
func(my_word='love')

you'll get:

default_msg
love

read more about *args and **kwargs in python: https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-python-3

Add more about default value if arg key is not assigned:

def make_hastie_10_2(n_samples=12000, random_state=None):
"""Generates data for binary classification used in
Hastie et al. 2009, Example 10.2. The ten features are standard independent Gaussian and
the target ``y`` is defined by:: y[i] = 1 if np.sum(X[i] ** 2) > 9.34 else -1 Read more in the :ref:`User Guide <sample_generators>`. Parameters
----------
n_samples : int, optional (default=12000)
The number of samples. random_state : int, RandomState instance or None (default)
Determines random number generation for dataset creation. Pass an int
for reproducible output across multiple function calls.
See :term:`Glossary <random_state>`. Returns
-------
X : array of shape [n_samples, 10]
The input samples. y : array of shape [n_samples]
The output values. References
----------
.. [1] T. Hastie, R. Tibshirani and J. Friedman, "Elements of Statistical
Learning Ed. 2", Springer, 2009. See also
--------
make_gaussian_quantiles: a generalization of this dataset approach
"""
rs = check_random_state(random_state) shape = (n_samples, 10)
X = rs.normal(size=shape).reshape(shape)
y = ((X ** 2.0).sum(axis=1) > 9.34).astype(np.float64, copy=False)
y[y == 0.0] = -1.0 return X, y

kwargs - Key words arguments in python function的更多相关文章

  1. Faiss in python and GPU报错:NotImplementedError: Wrong number or type of arguments for overloaded function 'new_GpuIndexFlatL2'.

    最近在玩faiss,运行这段代码的时候报错了: res = faiss.StandardGpuResources()flat_config = 0index = faiss.GpuIndexFlatL ...

  2. Mock an function to modify partial return value by special arguments on Python

    Mock an function to modify partial return value by special arguments on Python python mock一个带参数的方法,修 ...

  3. Python Function Note

    Python Function Note #汉诺塔问题Python实现 def my_move(n, a, b, c): if n == 1: print(a + ' --> ' + c) el ...

  4. redis学习 (key)键,Python操作redis 键 (二)

    # -*- coding: utf-8 -*- import redis #这个redis 连接不能用,请根据自己的需要修改 r =redis.Redis(host=") 1. delete ...

  5. python function with variadic arguments or keywords(dict) 可变参数与关键字参数

    *args 表示任意个普通参数,调用的时候自动组装为一个tuple **kwags 表示任意个字典类型参数, 调用的时候自动组装成一个dict args和kwags是两个约定俗成的用法. 变长参数可以 ...

  6. python function parameter

    Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...

  7. python Function

    Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...

  8. Default arguments and virtual function

    Predict the output of following C++ program. 1 #include <iostream> 2 using namespace std; 3 4 ...

  9. elike.python.function()

    将python用于基本的科学计算,能完全替代matlab.就最近写的一个物理模型程序来看,用python建立的物理模型的可控性,代码的层次性都优于matlab,只不过python没有matlab那样的 ...

随机推荐

  1. iOS即时通讯之CocoaAsyncSocket源码解析四

    原文 前言: 本文为CocoaAsyncSocket源码系列中第二篇:Read篇,将重点涉及该框架是如何利用缓冲区对数据进行读取.以及各种情况下的数据包处理,其中还包括普通的.和基于TLS的不同读取操 ...

  2. 【ABAP系列】SAP ABAP ALV里日期类型的F4帮助

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP ALV里日期类 ...

  3. mybatis如何把session托管给spring

    原生mybatis创建SqlSession的流程: SqlSession sqlSession = null; try { sqlSession = sqlSessionFactory.openSes ...

  4. HDU 1880 题解(字符串哈希)

    题面: 魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  5. Codeforces 601B(贪心+斜率+组合数学+单调栈)

    题面 传送门 题目大意: L(h)的值是区间[L,R]内,abs(h[i]-h[j])/(i-j)的最大值.现在有q个询问,每个询问表示询问区间[L,R]内,所有子序列的L(h)的值的和 分析 将|h ...

  6. SCUT - 297 - 狂符「幻视调律(Visionary Tuning)」 - 重链剖分

    https://scut.online/p/297 一般的树剖是关于点权的,但是突发奇想好像边权也是一样的.做一些小改动. #include<bits/stdc++.h> #define ...

  7. Java反射学习-3 - 反射获取属性,方法,构造器

    package cn.tx.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import ...

  8. Ubuntu14 vsftp 的安装和虚拟用户配置

    一.介绍 FTP 是 File Transfer Protocol (文件传输协议)的缩写 ,在 Unix/Linux 系统中常用的免费 FTP 服务器软件主要是 VSFTP,vsftp的官方地址:h ...

  9. Echarts数据可视化grid直角坐标系(xAxis、yAxis)详解:

    mytextStyle={ color:"#333", //文字颜色 fontStyle:"normal", //italic斜体 oblique倾斜 font ...

  10. jQuery——超链接提示

    在熟悉jQuery过程中,练习超链接提示显示,发现书本上有个问题,经过查询资料,修改如下: <!DOCTYPE html> <html> <head> <ti ...