Hi, I am learning Python. I wrote a simple two loops with if and else.
Here is my code:
for i in range(N):
....x = x_val[i].dot(self.w)
....x =np.max(x)
....s = np.exp(x)
....for y in range(M):
........if y == y_value[i]:
............res = s[y] + 1
........else:
............res = s[y]
I would like to combine if and else on one line for saving space.
........res = s[y] + 1 if y == y_value[i] else res = s[y]
But the syntaxError happens: cannot assign to condition expression.
Who knows the reason? Thanks
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here