mygrad.add#
- class mygrad.add(x1: ArrayLike, x2: ArrayLike, out: Tensor | ndarray | None = None, *, where: Mask = True, dtype: DTypeLikeReals = None, constant: bool | None = None)#
Add the arguments element-wise.
This docstring was adapted from that of numpy.add [1]
- Parameters:
- x1, x2ArrayLike
The arrays to be added. If
x1.shape != x2.shape
, they must be broadcastable to a common shape (which becomes the shape of the output). 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.
- dtypeOptional[DTypeLikeReals]
The dtype of the resulting tensor.
- outOptional[Union[ndarray, Tensor]]
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated tensor is returned.
- whereMask
This condition is broadcast over the input. At locations where the condition is True, the
out
tensor will be set to the ufunc result. Elsewhere, theout
tensor will retain its original value. Note that if an uninitialized out tensor is created via the defaultout=None
, locations within it where the condition is False will remain uninitialized.
- Returns:
- addTensor
The sum of x1 and x2, element-wise.
Notes
Equivalent to x1 + x2 in terms of tensor broadcasting.
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.add.html
Examples
>>> import mygrad as mg >>> mg.add(1.0, 4.0) Tensor(5.0) >>> x1 = mg.tensor([[0., 1., 2.], ... [3., 4., 5.], ... [6., 7., 8.]]) >>> x2 = mg.tensor([0., 1., 2.]) >>> mg.add(x1, x2) Tensor([[ 0., 2., 4.], [ 3., 5., 7.], [ 6., 8., 10.]])
- Attributes:
- signature
Methods
accumulate
([axis, dtype, out, constant])Not implemented
at
(indices[, b, constant])Not implemented
outer
(b, *[, dtype, out])Not Implemented
reduce
([axis, dtype, out, keepdims, ...])Not Implemented
reduceat
(indices[, axis, dtype, out])Not Implemented
resolve_dtypes
(dtypes, *[, signature, ...])Find the dtypes NumPy will use for the operation.
- __init__(*args, **kwargs)#
Methods
__init__
(*args, **kwargs)accumulate
([axis, dtype, out, constant])Not implemented
at
(indices[, b, constant])Not implemented
outer
(b, *[, dtype, out])Not Implemented
reduce
([axis, dtype, out, keepdims, ...])Not Implemented
reduceat
(indices[, axis, dtype, out])Not Implemented
resolve_dtypes
(dtypes, *[, signature, ...])Find the dtypes NumPy will use for the operation.
Attributes
identity
nargs
nin
nout
ntypes
signature
types