How to copy content of a numpy matrix to another?
<p>I have a simple question about basics of <code>python</code> and <code>numpy</code> module. I have a function as following:</p>

<pre><code>def update_x_last(self, x):
    self.x_last = x
</code></pre>

<p>The class attribute x_last and function argument x are both initialized as of type <code>numpy.matrix</code> and of the same shape. (<code>x.shape = x_last.shape = (4,1</code>)</p>

<p>I have noticed that the code above does not copy the content of the argument <code>x</code> to <code>x_last</code>, but it makes the object <code>x_last</code> point to the address of <code>x</code>.</p>

<p>However what I want to do is the following:</p>

<ul>
<li>Don't change the address of <code>self.x_last</code></li>
<li>Copy only the content of <code>x</code> to <code>self.x_last</code></li>
</ul>

<p>What is the best way to do this?</p>

<p><strong>Edit:</strong>
the requirement 'Don't change the address of 'self.x_last' was unimportant for me. The only required behaviour is the second requirement to copy only the content.</p>

<pre><code>import numpy as np

self.x_last = np.copy(x)
</code></pre>

python numpy matrix