How Julia loop works with vector?


Recently I have been encountering a problem that I want to make a vector that store the old matrix that I need to make my new matrix. However, in Julia while I change my new matrix, the old matrix follow. So, I wonder how should I do this step in Julia?

You should copy the vector if you need, well, a copy. There’s no automatic copy on assigment and all assignments has the semantic of binding to the reference of an object instead of copying.

3 Likes

y2 = copy(y), otherwise you set them to reference the same memory.

Thank you guys, that is very helpful