Numpy only supports operations one at a time. With that said, there are several workarounds.
Operations
The easiest solution is to use on-site operations with +=and*=
import numpy as np
import scipy
n = 100
b = 5.0
x = np.random.rand(n)
y = np.random.rand(n)
z = b * x
z += y
BLAS
BLAS . , , "AXPY",
y <- a * x + y
:
import scipy
axpy = scipy.linalg.blas.get_blas_funcs('axpy', arrays=(x, y))
axpy(x, y, n, b)
Numexpr
- , numexpr, :
import numexpr
z = numexpr.evaluate('b * x + y')
Theano
, theano. - :
import theano
x = theano.tensor.vector()
y = theano.tensor.vector()
out = b * x + y
f = theano.function([x, y], out)
z = f(x, y)