repeat#

ivy.repeat(x, /, repeats, *, axis=None, out=None)[source]#

Repeat values along a given dimension.

Parameters:
  • x (Union[Array, NativeArray]) – Input array.

  • repeats (Union[int, Iterable[int]]) – The number of repetitions for each element. repeats is broadcast to fit the shape of the given axis.

  • axis (Optional[int], default: None) – The axis along which to repeat values. By default, use the flattened input array, and return a flat output array.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The repeated output array.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([3, 4, 5])
>>> y = ivy.repeat(x, 2)
>>> print(y)
ivy.array([3, 3, 4, 4, 5, 5])
>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> y = ivy.repeat(x, [1, 2], axis=0)
>>> print(y)
ivy.array([[1, 2, 3],
           [4, 5, 6],
           [4, 5, 6]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]),
...                   b=ivy.array([0., 1., 2.]))
>>> y = ivy.repeat(x, 2, axis=0)
>>> print(y)
{
    a: ivy.array([0., 0., 1., 1., 2., 2.]),
    b: ivy.array([0., 0., 1., 1., 2., 2.])
}
Array.repeat(self, /, repeats, *, axis=None, out=None)[source]#

ivy.Array instance method variant of ivy.repeat. This method simply wraps the function, and so the docstring for ivy.repeat also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array.

  • repeats (Union[int, Iterable[int]]) – The number of repetitions for each element. repeats is broadcast to fit the shape of the given axis.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – The axis along which to repeat values. By default, use the flattened input array, and return a flat output array.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The repeated output array.

Examples

>>> x = ivy.array([0., 1., 2.])
>>> y= x.repeat(2)
>>> print(y)
ivy.array([0., 0., 1., 1., 2., 2.])
Container.repeat(self, /, repeats, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.repeat. This method simply wraps the function, and so the docstring for ivy.repeat also applies to this method with minimal changes.

Parameters:
  • x – Input container.

  • repeats (Union[int, Iterable[int], Container]) – The number of repetitions for each element. repeats is broadcast to fit the shape of the given axis.

  • axis (Optional[Union[int, Sequence[int], Container]], default: None) – The axis along which to repeat values. By default, use the flattened input array, and return a flat output array.

  • out (Optional[Container], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – The output container with repreated leaves.

Examples

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = x.repeat(2)
>>> print(y)
{
    a: ivy.array([0., 0., 1., 1., 2., 2.]),
    b: ivy.array([3., 3., 4., 4., 5., 5.])
}