-2

I am trying to Write the MSE function from Matlab to Python but I am getting this error:

 for i in range(len(RuleBase)):
^
IndentationError: unexpected indent

This is my python code:

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)
Narges Se
  • 35
  • 7
  • 1
    Google how to write for loops and how to write function definitions in python. White-space is important, and your error is saying that you've indented (e.g. put a tab) somewhere where Python isn't expecting to find one. – Ari Cooper-Davis Jun 10 '19 at 14:10

1 Answers1

2

Indentation is strictly enforced in python:

this should run:

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)     
  • 2
    After any function definition def Mse() , if statement or for loop etc you you include 4 spaces on the next line () according to official python guidelines (PEP 8). – time_is_a_drug Jun 09 '19 at 10:47