mygrad.add_sequence#
- mygrad.add_sequence(*variables: ArrayLike, constant: bool | None = None) Tensor [source]#
f(a, b, ...) -> a + b + ...
Add a sequence of tensors.
- Parameters:
- variablesArrayLike
A sequence of broadcast-compatible tensors. Non-tensor array-likes are treated as constants.
- constantOptional[bool]
If
True
, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e.constant.grad
will always returnNone
).Defaults to
False
for float-type data. Defaults toTrue
for integer-type data.Integer-type tensors must be constant.
- Returns:
- mygrad.Tensor
Notes
It is more efficient to back-propagate through this function than it is through a computational graph with N-1 corresponding addition operations.
Examples
>>> import mygrad as mg >>> x = mg.tensor([1. , 2.]) >>> y = mg.tensor([-1.]) >>> z = mg.tensor([[1.]]) >>> out = mg.add_sequence(x, y, z); out Tensor([[1., 2.]])
>>> out.backward() >>> x.grad array([1., 1.]) >>> y.grad array([2.]) >>> z.grad array([[2.]])