6 examples of 'tf reduce sum' in Python

Every line of 'tf reduce sum' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
176def reduce_sum(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None):
177 tf.reduce_sum(input_tensor, axis, keep_dims, name, reduction_indices)

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

614def sum(self, x: BKTensor, *args: Any, **kwargs: Any) -> BKTensor:
615 return self.tf.reduce_sum(x, *args, **kwargs)
488def sum(tensor, axis=None, **kw):
489 return _call_unary('sum', tensor, axis=axis, **kw)
47def sum(x, axis=None, keepdims=False):
48 return Sum(axis, keepdims)(x)
557def sum(x, axis=None, keepdims=False):
558 """Sum of the values in a tensor, alongside the specified axis.
559 """
560 return T.sum(x, axis=axis, keepdims=keepdims)
38def _SumGrad(op, grad):
39 """Gradient for Sum."""
40 # Fast path for when reducing to a scalar and ndims is known: adds only
41 # Reshape and Tile ops (and possibly a Shape).
42 if (op.inputs[0].get_shape().ndims is not None and
43 op.inputs[1].op.type == "Const"):
44 rank = op.inputs[0].get_shape().ndims
45 axes = tensor_util.MakeNdarray(op.inputs[1].op.get_attr("value"))
46 if np.array_equal(axes, np.arange(rank)): # Reduce all dims.
47 grad = array_ops.reshape(grad, [1] * rank)
48 # If shape is not fully defined (but rank is), we use Shape.
49 if op.inputs[0].get_shape().is_fully_defined():
50 input_shape = op.inputs[0].get_shape().as_list()
51 else:
52 input_shape = array_ops.shape(op.inputs[0])
53 return [array_ops.tile(grad, input_shape), None]
55 input_shape = array_ops.shape(op.inputs[0])
56 output_shape_kept_dims = math_ops.reduced_shape(input_shape, op.inputs[1])
57 tile_scaling = _safe_shape_div(input_shape, output_shape_kept_dims)
58 grad = array_ops.reshape(grad, output_shape_kept_dims)
59 return [array_ops.tile(grad, tile_scaling), None]

Related snippets