See if the following suits you:
import theano import theano.tensor as T m = T.matrix(dtype=theano.config.floatX) m_normalized = m / m.sum(axis=1).reshape((m.shape[0], 1)) f = theano.function([m], m_normalized) import numpy as np a = np.exp(np.random.randn(5, 10)).astype(theano.config.floatX) b = f(a) c = a / a.sum(axis=1)[:, np.newaxis] from numpy.testing import assert_array_equal assert_array_equal(b, c)
source share