[Numpy-discussion] Matrix addition, +=
Alan G Isaac
alan.isaac@gmail....
Mon Sep 12 06:58:31 CDT 2011
On 9/12/2011 7:18 AM, Jonas Wallin wrote:
> Why does
>
> MuY += MuY.transpose()
>
> and
>
> MuY = MuY + MuY.transpose()
>
> give different answers?
Because the first one is done in-place,
so you are changing MuY (and thus MuY.transpose)
as the operation proceeds.
MuY.transpose() is generally a *view* of MuY.
http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html
Use the second one.
Alan Isaac
More information about the NumPy-Discussion
mailing list