Ah, this is a very important thing, when working with a large amount of data. Here is what is going on/should be happening:
Line 1 is telling your program ahead of time: “This variable
x is going to be a matrix of size
m x n. Prepare this amount of space in memory to store the data.”
Line 2 is just some other matrix, serving as a way to make reading the code slightly easier.
Line 3 is rewriting the values of
x from line 1, using the values in
x0 stays the same. It is not over-written.
x is over-written, but it has been initialised, to avoid the scenario where you are increasing the size of
x by appending new values to it (this is bad for efficiency, as well as memory). Instead, every element of
x has already been allocated a place in memory, and the value of the element is just being changed.
Essentially, the above could be written as:
x = -2*np.random.rand(200,2)
x[100:200, :] = 1 + 2*np.random.rand(100,2)
Now, you are only re-writing half of the values of
x, but the memory pre-allocation is still useful.
I hope this was clear. It sounded muddled in my head.