I guess the assignment to c_train[i] might raise this error. Could you append the results to a list and use torch.stack on it instead?
PS: you can post code snippets by wrapping your code into three backticks ```, which would make debugging easier.