[Numpy-discussion] question about in-place operations

Robert Kern robert.kern at gmail.com
Tue May 22 10:59:31 EDT 2012

On Tue, May 22, 2012 at 3:47 PM, Massimo DiPierro
<massimo.dipierro at gmail.com> wrote:
> Thank you. I will look into numexpr.
> Anyway, I do not need arbitrary expressions. If there were something like
> numpy.add_scaled(a,scale,b)
> with support for scale in int, float, complex, this would be sufficient for me.

BLAS has the xAXPY functions, which will do this for float and complex.

import numpy as np
from scipy.linalg import fblas

def add_scaled_inplace(a, scale, b):
    if np.issubdtype(a.dtype, complex):
        fblas.zaxpy(b, a, a=scale)
        fblas.daxpy(b, a, a=scale)

Robert Kern

More information about the NumPy-Discussion mailing list