# chainer.functions.linear¶

chainer.functions.linear(x, W, b=None)[source]

Linear function, or affine transformation.

It accepts two or three arguments: an input minibatch x, a weight matrix W, and optionally a bias vector b. It computes

$Y = xW^\top + b.$
Parameters: x (Variable or numpy.ndarray or cupy.ndarray) – Input variable, which is a $$(s_B, s_1, s_2, ..., s_n)$$-shaped float array. Its first dimension $$(s_B)$$ is assumed to be the minibatch dimension. The other dimensions are treated as concatenated one dimension whose size must be $$(s_1 * ... * s_n = N)$$. W (Variable or numpy.ndarray or cupy.ndarray) – Weight variable of shape $$(M, N)$$, where $$(N = s_1 * ... * s_n)$$. b (Variable or numpy.ndarray or cupy.ndarray) – Bias variable (optional) of shape $$(M,)$$. Output variable. A float array with shape of $$(s_B, M)$$. Variable

Example

>>> x = np.random.uniform(0, 1, (3, 4)).astype(np.float32)
>>> W = np.random.uniform(0, 1, (5, 4)).astype(np.float32)
>>> b = np.random.uniform(0, 1, (5,)).astype(np.float32)
>>> y = F.linear(x, W, b)
>>> y.shape
(3, 5)