In some codes, I see people do .clone()
when operating on the same elements (e.g. grid[:, :, 0] = 2.0 * grid[:, :, 0].clone()
). From my view, those operations won’t cause an in-place operation. So I have the following questions.
- Why do people use
.clone()
when operating on the same elements? - When should we use
.clone()
except clone+detach && avoid inplace operation?