Откуда взялся «х»? ⇐ 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 == 'F1':
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, the function is referenced by '@' and the input for the function is 'x', but I don't know where the x comes from, so in the Python version, there is an error because of that.
What is the mistake and what should I do?
Источник: https://stackoverflow.com/questions/780 ... comes-from
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 == 'F1':
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, the function is referenced by '@' and the input for the function is 'x', but I don't know where the x comes from, so in the Python version, there is an error because of that.
What is the mistake and what should I do?
Источник: https://stackoverflow.com/questions/780 ... comes-from
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение