In the first case, when you use the assignment x = y , you set the memory cell x to the memory cell y , so basically x now just a redundant variable pointing to the same place in the memory that y points to. This way, it looks like you are creating a copy of your y matrix, but actually it is not. If after this job you had to work y and then print x and print y , you will see that they both change.
In the second case, since x initialized as an integer matrix, some automatic type casting is used so that the new values โโof each element of x are integer. In fact, you copy the values โโof your matrix y when using the assignment x[:,:] = y[:,:] , but since x is an integer matrix, Python basically does x[:,:] = int(y[:,:])
Instead, you can initialize x as follows:
x = matrix([[1.0, 2.0], [3.0, 4.0]])
or how:
x = matrix([[1, 2], [3, 4]], dtype='f')
and you will see the result expected after executing x[:,:] = y[:,:] .
source share