chainer.functions.linear¶
-
chainer.functions.
linear
(x, W, b=None, n_batch_axes=1)[source]¶ Linear function, or affine transformation.
It accepts two or three arguments: an input minibatch
x
, a weight matrixW
, and optionally a bias vectorb
. It computesyi=Wxi+b.- Parameters
x (
Variable
or N-dimensional array) – Input variable, which is a (s1,s2,...,sn)-shaped float array. Its firstn_batch_axes
dimensions are handled as minibatch dimensions. The other dimensions are handled as concatenated one dimension whose size must be (sn_batch_axes∗...∗sn=N).W (
Variable
or N-dimensional array) – Weight variable of shape (M,N), where (N=sn_batch_axes∗...∗sn).b (
Variable
or N-dimensional array) – Bias variable (optional) of shape (M,).n_batch_axes (int) – The number of batch axes. The default is 1. The input variable is reshaped into (n_batch_axes+1)-dimensional tensor. This should be greater than 0.
- Returns
Output variable. A float array with shape of (s1,...,sn_batch_axes,M).
- Return type
See also
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)