python - Add the elements in a row, for each row, in a matrix, using theano -
i have vector v , matrix z, say
v = theano.shared(rng.normal(0, 1, 10)) z = theano.shared(rng.normal(0, 1, (10, 10)))
i want create new vector y given v + sum of elements in each row of z. basically: y[i] = v[i] + t.sum(z[:,i]) can do, each entry, by:
y[i] = v[i] + theano.tensor.sum(z[:][i])
my question is: there way, without doing loop, write y = v + t.sum(rows of z) in 1 single line?
you can obtain this
y = v + z.sum(axis=1)
in numpy, , in theano, many aggregator functions, such sum
, mean
, var
, std
, any
, all
, ... have axis
keyword argument, , axes
keyword argument, can specify in direction array traversed.
Comments
Post a Comment