【发布时间】:2019-06-09 10:02:04
【问题描述】:
我正在尝试将 MSE 函数从 Matlab 转换为 Python,但出现此错误:
for i in range(len(RuleBase)):
^
IndentationError: unexpected indent
我已经尝试过使用空格,除了空格还有什么问题?
这是我在 matlab 中的函数:
function err=Mse(RuleBase,x1,x2)
temp=zeros(1,6);
Soogeno=zeros(49,4);
for i=1:length(RuleBase)
y=crisp(0,50,RuleBase(i,3),7);
temp(1,:)=RuleBase(i,:);
temp(1,3)=y;
Soogeno(i,:)=temp(1,1:4);
end
这是我的python代码:
def Mse(RuleBase,x1,x2):
temp=np.zeros(shape = (1,6))
soogeno=np.zeros(shape = (49,4))
for i in range(len(RuleBase)):
y=crisp(m=0,M=50,fy=RuleBase[i,3],n=7)
temp[0]=RuleBase[i]
temp[0,2]=y
Soogeno[i]=temp[0,0:3]
return(soogeno)
【问题讨论】:
-
谷歌如何编写for循环以及如何在python中编写函数定义。空格很重要,你的错误是说你在 Python 不希望找到的地方缩进(例如放一个制表符)。
标签: python arrays matlab fuzzy-logic mse