Что должно быть входными данными для функции? ⇐ Python
-
Гость
Что должно быть входными данными для функции?
This is part of a code from COA.
This code is the original one in matlab:
function [lowerbound,upperbound,dimension,fitness] = fun_info(F) switch F case '1' fitness = @F1; lowerbound=-100; upperbound=100; dimension=30; . . . end end % F1 function R = F1(x) R=sum(x.^2); end . . . and this code is what I wrote in python:
def fun_info(fun_name): if fun_name == 1: fitness = function1() lowerbound = -100 upperbound = 100 dimension = 30 . . . else: raise ValueError("Function not defined.") return lowerbound, upperbound, dimension, fitness def function1(x): r = np.sum(np.square(x)) return r . . . in the matlab code, function is called by '@' and the input for function is 'x', but I dont know where the x comes from, so in the python version there is an error because of that. What is the mistake and what shoud I do?
Источник: https://stackoverflow.com/questions/780 ... e-function
This is part of a code from COA.
This code is the original one in matlab:
function [lowerbound,upperbound,dimension,fitness] = fun_info(F) switch F case '1' fitness = @F1; lowerbound=-100; upperbound=100; dimension=30; . . . end end % F1 function R = F1(x) R=sum(x.^2); end . . . and this code is what I wrote in python:
def fun_info(fun_name): if fun_name == 1: fitness = function1() lowerbound = -100 upperbound = 100 dimension = 30 . . . else: raise ValueError("Function not defined.") return lowerbound, upperbound, dimension, fitness def function1(x): r = np.sum(np.square(x)) return r . . . in the matlab code, function is called by '@' and the input for function is 'x', but I dont know where the x comes from, so in the python version there is an error because of that. What is the mistake and what shoud I do?
Источник: https://stackoverflow.com/questions/780 ... e-function