How do I write the code below in a list comprehension style?
Residual = np.zeros((noRows, noRows))
Dist = np.zeros((noRows, noRows))
for i in range(noRows):
for j in range(noRows):
Residual[i][j] = (data[data.columns[2]][i]-data[data.columns[2]][j])**2
Dist[i][j] = (data[data.columns[0]][i]-data[data.columns[1]][j])**2
We don't have full code, but from what I can see from your snippet, solution should be something like this:
For example:
Output will be:
In your case the statement will be way more complicated compared to "i+j" operation.... but list comprehension should be right.