chainer.functions.sum¶
-
chainer.functions.
sum
(x, axis=None, keepdims=False)[source]¶ Sum of array elements over a given axis.
- Parameters
x (
Variable
or N-dimensional array) – Elements to sum. A (s1,s2,...,sN) -shaped float array.axis (None, int, or tuple of int) – Axis along which a sum is performed. The default (axis = None) is perform a sum over all the dimensions of the input array.
keepdims (bool) – If
True
, the specified axes are remained as axes of length one.
- Returns
Output variable.
- Return type
Example
>>> x = np.arange(6).reshape(2,3).astype(np.float32) >>> x array([[0., 1., 2.], [3., 4., 5.]], dtype=float32) >>> y = F.sum(x) >>> y.shape () >>> y.array array(15., dtype=float32) >>> y = F.sum(x, axis=1) >>> y.shape (2,) >>> y.array array([ 3., 12.], dtype=float32) >>> y = F.sum(x, keepdims=True) >>> y.shape (1, 1) >>> y.array array([[15.]], dtype=float32)