Week2 Programming Assignment Ex 6: Optimise Function

And the reason the copy is done in the first place is that objects are passed “by reference” on function calls in python. So the w down in optimize is a reference to the same global w that was passed in, unless you do the copy to break that link. Having a subroutine modify global data is something you only want to do “on purpose”, not “by accident”. It would be a pretty nasty surprise if that’s not what you were intending.

Here’s a thread which discusses this general issue as it relates to the “update parameters” routines in Weeks 3 and 4.