Hi,
Yes this line: self.hidden[self.iteration] = XXX is modifying the hidden state inplace which leads to the error you see.
Do you actually want to learn the hidden state here? because it seems that you overwrite the value that you were supposed to learn.