[SciPy-user] Mathematica Element-wise Multiplication

Alan G Isaac aisaac@american....
Fri Dec 21 11:34:00 CST 2007


On Wed, 19 Dec 2007, Erik Volz apparently wrote:
> z+=z.T # where dimension z > 1 
> which does not do what a naive user would think it does (try it). 

You mean like this? ::

    >>> x=N.ones( (2,2) )
    >>> x
    array([[ 1.,  1.],
           [ 1.,  1.]])
    >>> x += x.T
    >>> x
    array([[ 2.,  2.],
           [ 3.,  2.]])

That just shows you that the in-place updating takes place 
in row major order.  You have to have something like this
or create temporary arrays, but not creating temporary
arrays is a core value of the in-place operators.

If you do not like them, do not use them.
Or force the creation of a temporary array on the RHS::

     >>> x=N.ones( (2,2) )
     >>> x += x.T + 0
     >>> x
     array([[ 2.,  2.],
            [ 2.,  2.]])

Cheers,
Alan Isaac





More information about the SciPy-user mailing list