mygrad.repeat#
- mygrad.repeat(a: ArrayLike, repeats: int | Sequence[int], axis: int | None = None, *, constant: bool | None = None) Tensor [source]#
Repeat elements of a tensor.
This docstring was adapted from
numpy.repeat
- Parameters:
- aArrayLike
Input tensor.
- repeatsUnion[int, Sequence[int]]
The number of repetitions for each element.
repeats
is broadcasted to fit the shape of the given axis.- axisOptional[int]
The axis along which to repeat values. By default, use the flattened input array, and return a flat output tensor.
- 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
- ——-
- repeated_tensorTensor
Output tensor which has the same shape as a, except along the given axis.
Examples
>>> import mygrad as mg >>> mg.repeat(3, 4) Tensor([3, 3, 3, 3]) >>> x = mg.Tensor([[1, 2], [3, 4]]) >>> mg.repeat(x, 2) Tensor([1, 1, 2, 2, 3, 3, 4, 4]) >>> mg.repeat(x, 3, axis=1) Tensor([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> mg.repeat(x, [1, 2], axis=0) Tensor([[1, 2], [3, 4], [3, 4]])