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):...


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.


....for y in range(M):


........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



Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here