简体   繁体   English

如何定义Function参数随输入文件变化?

[英]How Can I Define a Function Whose Parameters Change According to Input File?

I have a CBR function which takes 4 parameters like我有一个 CBR function 它需要 4 个参数,例如
CBR (w1,w2,w3,w4,x_train,y_train) w1 to wn changes according to the input file. CBR (w1,w2,w3,w4,x_train,y_train) w1 到 wn 根据输入文件变化。 w1 to wn are weights of independent parameters. w1 到 wn 是独立参数的权重。 Thus, according to the input file and the size of the input parameters, w1 to wn changes (N size of input parameters).因此,根据输入文件和输入参数的大小,w1 到 wn 会发生变化(输入参数的大小为 N)。 How can I define such a function?如何定义这样的 function? Could you give me an example?你能给我举个例子吗? Thanks谢谢

To pass a variable number of arguments you can use要传递可变数量的 arguments,您可以使用

def CBR(x_train, y_train, *args):
   ...

The special syntax *args is used to pass a variable number of arguments to a function.特殊语法*args用于将可变数量的 arguments 传递给 function。

The syntax is to use the symbol * to take in a variable number of arguments;语法是使用符号*来接收可变数量的 arguments; by convention, it is often used with the word args but you can use w if you prefer.按照惯例,它通常与args一词一起使用,但如果您愿意,也可以使用w

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何定义输入为列名的 function? - How to define a function whose input is a column name? 如何为此输入定义 python function - How can I define python function for this input 如何根据案例数量分隔输入文件? - How can I seperate the input file according to the number of cases? 如何定义名称,然后在python中读取文件时更改名称 - How can I define a name and then change it while reading a file in python 如何使用初始值递归地将参数输入到此函数中? - How can I recursively input parameters into this function with an initial value? 如何在此代码中使用 Input() function 更改文件名? 此代码的任何正确形式 - how can i change the file name using Input() function in this code ? any correct form of this code 如何定义两种根据输入进行迭代的方式 - How to define two ways of iterate according input 如何在 Python 中定义具有默认参数值和可选参数的函数? - How can I define a function with default parameter values and optional parameters in Python? 如何在 Python 中对代码块进行分组,类似于函数,但无需定义参数? - How can I group a block of code in Python, similar to function, but without the need to define the parameters? GraphQL:如何定义输入参数/约束 - GraphQL: How do I define input parameters/constraints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM