[Numpy-discussion] Support of '@='?
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Wed Jun 22 14:32:54 EDT 2016
>
> Just if you are curious why it is an error at the moment. We can't have
> it be filled in by python to be not in-place (`M = M @ P` meaning), but
> copying over the result is a bit annoying and nobody was quite sure
> about it, so it was delayed.
The problem with using out in-place is clear from trying `np.matmul(a, a,
out=a)`:
```
In [487]: a
array([[ 1. , 0. , 0. ],
[ 0. , 0.8660254, 0.5 ],
[ 0. , -0.5 , 0.8660254]])
In [488]: np.matmul(a, a)
Out[488]:
array([[ 1. , 0. , 0. ],
[ 0. , 0.5 , 0.8660254],
[ 0. , -0.8660254, 0.5 ]])
In [489]: np.matmul(a, a, out=a)
Out[489]:
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
```
It would seem hard to avoid doing the copying (though obviously one should
iterate over higher dimensiones, ie., temp.shape = M.shape[-2:]). Not
dissimilar from cumsum etc which are also not true ufuncs (but where things
can be made to work by ensuring operations are doing in the right order).
-- Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160622/878d5bda/attachment.html>
More information about the NumPy-Discussion
mailing list