How Julia loop works with vector?

question

#1


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?


#2

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

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


#4

Thank you guys, that is very helpful