Manipulation#

class ivy.data_classes.container.manipulation._ContainerWithManipulation(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, build_callable=False, **kwargs)[source]#

Bases: ContainerBase

_abc_impl = <_abc._abc_data object>#
static _static_clip(x, x_min=None, x_max=None, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Union[Array, NativeArray, Container]) – Input array or container containing elements to clip.

  • x_min (Optional[Union[Number, Array, NativeArray, Container]], default: None) – Minimum value.

  • x_max (Optional[Union[Number, Array, NativeArray, Container]], default: None) – Maximum value.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – A container with the elements of x, but where values < x_min are replaced with x_min, and those > x_max with x_max.

Examples

With one ivy.Container input:

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

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]),
...                   b=ivy.array([3., 4., 5.]))
>>> x_min = ivy.Container(a=0, b=0)
>>> x_max = ivy.Container(a=1, b=1)
>>> y = ivy.Container.static_clip(x, x_min, x_max)
>>> print(y)
{
    a: ivy.array([0., 1., 1.]),
    b: ivy.array([1., 1., 1.])
}
static _static_concat(xs, /, *, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container static method variant of ivy.concat.

This method simply wraps the function, and so the docstring for ivy.concat also applies to this method with minimal changes.

Return type:

Container

static _static_constant_pad(x, /, pad_width, *, value=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – Input container with leaves to pad.

  • pad_width (Union[Iterable[Tuple[int]], Container]) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.

  • value (Union[Number, Container], default: 0) – The constant value to pad the array with.

  • 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 – Output container with padded array leaves of rank equal to x with shape increased according to pad_width.

Examples

>>> x = ivy.Container(a = ivy.array([1, 2, 3]), b = ivy.array([4, 5, 6]))
>>> y = ivy.Container.static_constant_pad(x, pad_width = [[2, 3]])
>>> print(y)
{
    a: ivy.array([0, 0, 1, 2, 3, 0, 0, 0]),
    b: ivy.array([0, 0, 4, 5, 6, 0, 0, 0])
}
static _static_expand_dims(x, /, *, copy=None, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – input container.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Union[int, Sequence[int], Container], default: 0) – position where a new axis (dimension) of size one will be added. If an element of the container has the rank of N, then the axis needs to be between [-N-1, N]. Default: 0.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – A container with the elements of x, but with the dimensions of its elements added by one in a given axis.

Examples

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., 1.]),
...                   b=ivy.array([3., 4.]),
...                   c=ivy.array([6., 7.]))
>>> y = ivy.Container.static_expand_dims(x, axis=1)
>>> print(y)
{
    a: ivy.array([[0.],
                  [1.]]),
    b: ivy.array([[3.],
                  [4.]]),
    c: ivy.array([[6.],
                  [7.]])
}

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]),
...                   b=ivy.array([3., 4., 5.]),
...                   c=ivy.array([6., 7., 8.]))
>>> container_axis = ivy.Container(a=0, b=-1, c=(0,1))
>>> y = ivy.Container.static_expand_dims(x, axis=container_axis)
>>> print(y)
{
    a: ivy.array([[0., 1., 2.]]),
    b: ivy.array([[3.],
                  [4.],
                  [5.]]),
    c: ivy.array([[[6., 7., 8.]]])
}
static _static_flip(x, /, *, copy=None, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – input container.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Optional[Union[int, Sequence[int], Container]], default: None) – axis (or axes) along which to flip. If axis is None, all input array axes are flipped. If axis is negative, axis is counted from the last dimension. If provided more than one axis, only the specified axes. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container having the same data type and shape as x and whose elements, relative to x, are reordered.

Examples

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),
...                   b=ivy.array([2, 3, 4]))
>>> y = ivy.Container.static_flip(x)
>>> print(y)
{
    a: ivy.array([1, 0, -1]),
    b: ivy.array([4, 3, 2])
}
>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),
...                   b=ivy.array([2, 3, 4]))
>>> y = ivy.Container.static_flip(x, axis=0)
>>> print(y)
{
    a: ivy.array([1, 0, -1]),
    b: ivy.array([4, 3, 2])
}
static _static_permute_dims(x, /, axes, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – input container.

  • axes (Union[Tuple[int, ...], Container]) – tuple containing a permutation of (0, 1, …, N-1) where N is the number of axes (dimensions) of x.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

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

Return type:

Container

Returns:

ret – A container with the elements of self permuted along the given axes.

Examples

>>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b=ivy.array([[3., 4., 5.]]))
>>> y = ivy.Container.static_permute_dims(x, axes=(1, 0))
>>> print(y)
{
    a:ivy.array([[0.],[1.],[2.]]),
    b:ivy.array([[3.],[4.],[5.]])
}
static _static_repeat(x, /, repeats, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container static 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.

Return type:

Container

Examples

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = ivy.Container.static_repeat(2)
>>> print(y)
{
    a: ivy.array([0., 0., 1., 1., 2., 2.]),
    b: ivy.array([3., 3., 4., 4., 5., 5.])
}
static _static_reshape(x, /, shape, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, copy=None, out=None, order='C', allowzero=True)[source]#

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

Parameters:
  • x (Union[Array, NativeArray, Container]) – input container.

  • shape (Union[Shape, NativeShape, Sequence[int], Container]) – The new shape should be compatible with the original shape. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • copy – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

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

  • order (Union[str, Container], default: 'C') – Read the elements of x using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is ‘C’

Return type:

Container

Returns:

ret – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Examples

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]),
...                   b=ivy.array([0, 1, 2, 3, 4, 5]))
>>> y = ivy.Container.static_reshape(x, (3,2))
>>> print(y)
{
    a: ivy.array([[0, 1],
                  [2, 3],
                  [4, 5]]),
    b: ivy.array([[0, 1],
                  [2, 3],
                  [4, 5]])
}
>>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]),
...                   b=ivy.array([0, 1, 2, 3, 4, 5]))
>>> y = ivy.Container.static_reshape(x, (3,2), order='F')
>>> print(y)
{
    a: ivy.array([[0, 3],
                  [1, 4],
                  [2, 5]]),
    b: ivy.array([[0, 3],
                  [1, 4],
                  [2, 5]])
}
static _static_roll(x, /, shift, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Union[Array, NativeArray, Container]) – input container.

  • shift (Union[int, Tuple[int, ...], Container]) – number of places by which the elements are shifted. If shift is a tuple, then axis must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in shift. If shift is an int and axis a tuple, then the same shift must be used for all specified axes. If a shift is positivclipe, then array elements must be shifted positively (toward larger indices) along the dimension of axis. If a shift is negative, then array elements must be shifted negatively (toward smaller indices) along the dimension of axis.

  • axis (Optional[Union[int, Tuple[int, ...], Container]], default: None) – axis (or axes) along which elements to shift. If axis is None, the array must be flattened, shifted, and then restored to its original shape. Default None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container having the same data type as x and whose elements, relative to x, are shifted.

Examples

With one ivy.Container input:

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

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]),
...                   b=ivy.array([3., 4., 5.]))
>>> shift = ivy.Container(a=1, b=-1)
>>> y = ivy.Container.static_roll(x, shift)
>>> print(y)
{
    a: ivy.array([2., 0., 1.]),
    b: ivy.array([4., 5., 3.])
}
static _static_split(x, /, *, copy=None, num_or_size_splits=None, axis=0, with_remainder=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • x (Union[Container, Array, NativeArray]) – array to be divided into sub-arrays.

  • num_or_size_splits (Optional[Union[int, Sequence[int], Array, NativeArray, Container]], default: None) – Number of equal arrays to divide the array into along the given axis if an integer. The size of each split element if a sequence of integers or 1-D array. Default is to divide into as many 1-dimensional arrays as the axis dimension.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Union[int, Container], default: 0) – The axis along which to split, default is 0.

  • with_remainder (Union[bool, Container], default: False) – If the tensor does not split evenly, then store the last remainder entry. Default is False.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

List[Container]

Returns:

list of containers of sub-arrays.

Examples

>>> x = ivy.Container(a=ivy.array([2, 1, 5, 9]), b=ivy.array([3, 7, 2, 11]))
>>> y = ivy.Container.static_split(x, num_or_size_splits=2)
>>> print(y)
[{
    a: ivy.array([2, 1]),
    b: ivy.array([3, 7])
}, {
    a: ivy.array([5, 9]),
    b: ivy.array([2, 11])
}]
static _static_squeeze(x, /, axis, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – input container.

  • axis (Union[int, Sequence[int], Container]) – axis (or axes) to squeeze.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container with the results.

Examples

>>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]),
...                   b=ivy.array([[[11.], [12.]]]))
>>> y = ivy.Container.static_squeeze(x, 0)
>>> print(y)
{
    a: ivy.array([[10., 11.]]),
    b: ivy.array([[11., 12.]])
}
>>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]),
...                   b=ivy.array([[[11.], [12.]]]))
>>> y = ivy.Container.static_squeeze(x, [0, 2])
>>> print(y)
{
    a: ivy.array([[10.], [11.]]),
    b: ivy.array([[11.], [12.]])
}
static _static_stack(xs, /, *, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • xs (Union[Tuple[Union[Array, NativeArray, Container]], List[Union[Array, NativeArray, Container]]]) – Container with leaves to join. Each array leavve must have the same shape.

  • axis (Union[int, Container], default: 0) – axis along which the array leaves will be joined. More details can be found in the docstring for ivy.stack.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 – an output container with the results.

Examples

>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> z = ivy.Container.static_stack(x,axis = 1)
>>> print(z)
{
    a: ivy.array([[0, 2],
                [1, 3]]),
    b: ivy.array([[4],
                [5]])
}
>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]]))
>>> z = ivy.Container.static_stack([x,y])
>>> print(z)
{
    a: ivy.array([[[0, 1],
                [2, 3]],
                [[3, 2],
                [1, 0]]]),
    b: ivy.array([[[4, 5]],
                [[1, 0]]])
}
>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]]))
>>> z = ivy.Container.static_stack([x,y],axis=1)
>>> print(z)
{
    a: ivy.array([[[0, 1],
                [3, 2]],
                [[2, 3],
                [1, 0]]]),
    b: ivy.array([[[4, 5],
                [1, 0]]])
}
static _static_swapaxes(x, axis0, axis1, /, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – Input container

  • axis0 (Union[int, Container]) – First axis to be swapped.

  • axis1 (Union[int, Container]) – Second axis to be swapped.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • 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 – x with its axes permuted.

  • >>> a = ivy.array([[1, 2, 3], [4, 5, 6]])

  • >>> b = ivy.array([[7, 8, 9], [10, 11, 12]])

  • >>> x = ivy.Container(a = a, b = b)

  • >>> y = x.swapaxes(0, 1)

  • >>> print(y)

  • {

    a: ivy.array([[1, 4],

    [2, 5], [3, 6]]),

    b: ivy.array([[7, 10],

    [8, 11], [9, 12]])

  • }

static _static_tile(x, /, repeats, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – Input Container.

  • repeats (Union[Iterable[int], Container]) – The number of repetitions of x along each axis.

  • 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 container output with tiled leaves.

Examples

>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> y = ivy.Container.static_tile((2,3))
>>> print(y)
{
    a: ivy.array([[0,1,0,1,0,1],
                  [2,3,2,3,2,3],
                  [0,1,0,1,0,1],
                  [2,3,2,3,2,3]]),
    b: ivy.array([[4,5,4,5,4,5],
                  [4,5,4,5,4,5]])
}
static _static_unstack(x, /, *, copy=None, axis=0, keepdims=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • x (Union[Array, NativeArray, Container]) – Input array or container to unstack.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Union[int, Container], default: 0) – Axis for which to unpack the array.

  • keepdims (Union[bool, Container], default: False) – Whether to keep dimension 1 in the unstack dimensions. Default is False.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

Container

Returns:

ret – List of arrays, unpacked along specified dimensions, or containers with arrays unpacked at leaves

Examples

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
                    b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]]))
>>> y = ivy.Container.static_unstack(x, axis=0)
>>> print(y)
[{
    a: ivy.array([[1, 2],
                 [3, 4]]),
    b: ivy.array([[9, 10],
                 [11, 12]])
}, {
    a: ivy.array([[5, 6],
                 [7, 8]]),
     b: ivy.array([[13, 14],
                  [15, 16]])
}]
>>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
                    b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]]))
>>> y = ivy.Container.static_unstack(x, axis=1, keepdims=True)
>>> print(y)
[{
    a: ivy.array([[[1, 2]],
                 [[5, 6]]]),
    b: ivy.array([[[9, 10]],
                 [[13, 14]]])
}, {
    a: ivy.array([[[3, 4]],
                 [[7, 8]]]),
    b: ivy.array([[[11, 12]],
                 [[15, 16]]])
}]
static _static_zero_pad(x, /, pad_width, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • x (Container) – Input array to pad.

  • pad_width (Union[Iterable[Tuple[int]], Container]) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 – Padded array of rank equal to x with shape increased according to pad_width.

Examples

With ivy.Container input:

>>> x = ivy.Container(a = ivy.array([1., 2., 3.]), b = ivy.array([3., 4., 5.]))
>>> y = ivy.zero_pad(x, pad_width = [[2, 3]])
>>> print(y)
{
    a: ivy.array([0., 0., 1., 2., 3., 0., 0., 0.]),
    b: ivy.array([0., 0., 3., 4., 5., 0., 0., 0.])
}
clip(x_min=None, x_max=None, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input container containing elements to clip.

  • x_min (Optional[Union[Number, Array, NativeArray, Container]], default: None) – Minimum value.

  • x_max (Optional[Union[Number, Array, NativeArray, Container]], default: None) – Maximum value.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – A container with the elements of x, but where values < x_min are replaced with x_min, and those > x_max with x_max.

Examples

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = x.clip(1,2)
>>> print(y)
{
    a: ivy.array([1., 1., 2.]),
    b: ivy.array([2., 2., 2.])
}
concat(xs, *, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.concat.

This method simply wraps the function, and so the docstring for ivy.concat also applies to this method with minimal changes.

Return type:

Container

constant_pad(pad_width, *, value=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input container with leaves to pad.

  • pad_width (Union[Iterable[Tuple[int]], Container]) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.

  • value (Union[Number, Container], default: 0) – The constant value to pad the array with.

  • 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 – Output container with padded array leaves of rank equal to x with shape increased according to pad_width.

Examples

>>> x = ivy.Container(a = ivy.array([1, 2, 3]), b = ivy.array([4, 5, 6]))
>>> y = x.constant_pad(pad_width = [[2, 3]])
>>> print(y)
{
    a: ivy.array([0, 0, 1, 2, 3, 0, 0, 0]),
    b: ivy.array([0, 0, 4, 5, 6, 0, 0, 0])
}
expand_dims(*, copy=None, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Union[int, Sequence[int], Container], default: 0) – position where a new axis (dimension) of size one will be added. If an element of the container has the rank of N, the axis needs to be between [-N-1, N]. Default: 0.

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

Return type:

Container

Returns:

ret – A container with the elements of self, but with the dimensions of its elements added by one in a given axis.

Examples

>>> x = ivy.Container(a=ivy.array([[0., 1.],
...                                [2., 3.]]),
...                   b=ivy.array([[4., 5.],
...                                [6., 7.]]))
>>> y = x.expand_dims(axis=1)
>>> print(y)
{
    a: ivy.array([[[0., 1.]],
                  [[2., 3.]]]),
    b: ivy.array([[[4., 5.]],
                  [[6., 7.]]])
}
flip(*, copy=None, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Optional[Union[int, Sequence[int], Container]], default: None) – axis (or axes) along which to flip. If axis is None, all input array axes are flipped. If axis is negative, axis is counted from the last dimension. If provided more than one axis, only the specified axes. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container having the same data type and shape as self and whose elements, relative to self, are reordered.

Examples

With one ivy.Container input:

>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),
...                   b=ivy.array([2, 3, 4]))
>>> y = x.flip()
>>> print(y)
{
    a: ivy.array([1, 0, -1]),
    b: ivy.array([4, 3, 2])
}
>>> x = ivy.Container(a=ivy.array([-1, 0, 1]),
...                   b=ivy.array([2, 3, 4]))
>>> y = x.flip(axis=0)
>>> print(y)
{
    a: ivy.array([1, 0, -1]),
    b: ivy.array([4, 3, 2])
}
permute_dims(axes, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • axes (Union[Tuple[int, ...], Container]) – tuple containing a permutation of (0, 1, …, N-1) where N is the number of axes (dimensions) of x.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

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

Return type:

Container

Returns:

ret – A container with the elements of self permuted along the given axes.

Examples

>>> x = ivy.Container(a=ivy.array([[0., 1., 2.]]), b=ivy.array([[3., 4., 5.]]))
>>> y = x.permute_dims(axes=(1, 0))
>>> print(y)
{
    a:ivy.array([[0.],[1.],[2.]]),
    b:ivy.array([[3.],[4.],[5.]])
}
repeat(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.])
}
reshape(shape, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, copy=None, order='C', allowzero=True, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • shape (Union[Shape, NativeShape, Sequence[int], Container]) – The new shape should be compatible with the original shape. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • copy – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • order (Union[str, Container], default: 'C') – Read the elements of the input container using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of indexing. Default order is ‘C’

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

Return type:

Container

Returns:

ret – an output container having the same data type as self and elements as self.

Examples

>>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]),
...                   b=ivy.array([0, 1, 2, 3, 4, 5]))
>>> y = x.reshape((2,3))
>>> print(y)
{
    a: ivy.array([[0, 1, 2],
                  [3, 4, 5]]),
    b: ivy.array([[0, 1, 2],
                  [3, 4, 5]])
}
>>> x = ivy.Container(a=ivy.array([0, 1, 2, 3, 4, 5]),
...                   b=ivy.array([0, 1, 2, 3, 4, 5]))
>>> y = x.reshape((2,3), order='F')
>>> print(y)
{
    a: ivy.array([[0, 2, 4],
                  [1, 3, 5]]),
    b: ivy.array([[0, 2, 4],
                  [1, 3, 5]])
}
roll(shift, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • shift (Union[int, Sequence[int], Container]) – number of places by which the elements are shifted. If shift is a tuple, then axis must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element in shift. If shift is an int and axis a tuple, then the same shift must be used for all specified axes. If a shift is positive, then array elements must be shifted positively (toward larger indices) along the dimension of axis. If a shift is negative, then array elements must be shifted negatively (toward smaller indices) along the dimension of axis.

  • axis (Optional[Union[int, Sequence[int], Container]], default: None) – axis (or axes) along which elements to shift. If axis is None, the array must be flattened, shifted, and then restored to its original shape. Default None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container having the same data type as self and whose elements, relative to self, are shifted.

Examples

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = x.roll(1)
>>> print(y)
{
    a: ivy.array([2., 0., 1.]),
    b: ivy.array([5., 3., 4.])
}
split(*, copy=None, num_or_size_splits=None, axis=0, with_remainder=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Container) – array to be divided into sub-arrays.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • num_or_size_splits (Optional[Union[int, Sequence[int], Array, NativeArray, Container]], default: None) – Number of equal arrays to divide the array into along the given axis if an integer. The size of each split element if a sequence of integers or 1-D array. Default is to divide into as many 1-dimensional arrays as the axis dimension.

  • axis (Union[int, Container], default: 0) – The axis along which to split, default is 0.

  • with_remainder (Union[bool, Container], default: False) – If the tensor does not split evenly, then store the last remainder entry. Default is False.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

List[Container]

Returns:

list of containers of sub-arrays.

Examples

>>> x = ivy.Container(a=ivy.array([2, 1, 5, 9]), b=ivy.array([3, 7, 2, 11]))
>>> y = x.split(num_or_size_splits=2)
>>> print(y)
[{
    a: ivy.array([2, 1]),
    b: ivy.array([3, 7])
}, {
    a: ivy.array([5, 9]),
    b: ivy.array([2, 11])
}]
squeeze(*, axis, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container.

  • axis (Optional[Union[int, Sequence[int], Container]]) – axis (or axes) to squeeze.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

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

Return type:

Container

Returns:

ret – an output container with the results.

Examples

>>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]),
...                   b=ivy.array([[[11.], [12.]]]))
>>> y = x.squeeze(axis=2)
>>> print(y)
{
    a: ivy.array([[10., 11.]]),
    b: ivy.array([[11., 12.]])
}
>>> x = ivy.Container(a=ivy.array([[[10.], [11.]]]),
...                   b=ivy.array([[[11.], [12.]]]))
>>> y = x.squeeze(axis=0)
>>> print(y)
{
    a: ivy.array([[10.],
                  [11.]]),
    b: ivy.array([[11.],
                  [12.]])
}
stack(xs, *, axis=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) –

    Container with leaves to join with leaves of other arrays/containers.

    Each array leave must have the same shape.

  • xs (Union[Tuple[Union[Array, NativeArray, Container]], List[Union[Array, NativeArray, Container]]]) – Container with other leaves to join. Each array leave must have the same shape.

  • axis (Union[int, Container], default: 0) – axis along which the array leaves will be joined. More details can be found in the docstring for ivy.stack.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 – an output container with the results.

Examples

>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> y = ivy.Container(a=ivy.array([[3, 2], [1,0]]), b=ivy.array([[1, 0]]))
>>> x.stack([y])
{
    a: ivy.array([[[0, 1],
                [2, 3]],
                [[3, 2],
                [1, 0]]]),
    b: ivy.array([[[4, 5]],
                [[1, 0]]])
}
swapaxes(axis0, axis1, /, *, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input container.

  • axis0 (Union[int, Container]) – First axis to be swapped.

  • axis1 (Union[int, Container]) – Second axis to be swapped.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • 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 – x with its axes permuted.

Examples

>>> a = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> b = ivy.array([[7, 8, 9], [10, 11, 12]])
>>> x = ivy.Container(a = a, b = b)
>>> y = x.swapaxes(0, 1)
>>> print(y)
{
    a: ivy.array([[1, 4],
                  [2, 5],
                  [3, 6]]),
    b: ivy.array([[7, 10],
                  [8, 11],
                  [9, 12]])
}
tile(repeats, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input container.

  • repeats (Union[Iterable[int], Container]) – The number of repetitions of x along each axis.

  • 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 container output with tiled leaves.

Examples

>>> x = ivy.Container(a=ivy.array([[0, 1], [2,3]]), b=ivy.array([[4, 5]]))
>>> y = x.tile((2,3))
>>> print(y)
{
    a: (<class ivy.data_classes.array.array.Array> shape=[4, 6]),
    b: (<class ivy.data_classes.array.array.Array> shape=[2, 6])
}
unstack(*, copy=None, axis=0, keepdims=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Container) – Input container to unstack at leaves.

  • copy (Optional[Union[bool, Container]], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default: None.

  • axis (Union[int, Container], default: 0) – Axis for which to unpack the array.

  • keepdims (Union[bool, Container], default: False) – Whether to keep dimension 1 in the unstack dimensions. Default is False.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

Container

Returns:

ret – Containers with arrays unpacked at leaves

Examples

With one ivy.Container instances:

>>> x = ivy.Container(a=ivy.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]),
                    b=ivy.array([[[9, 10], [11, 12]], [[13, 14], [15, 16]]]))
>>> x.unstack(axis=0)
[{
    a: ivy.array([[1, 2],
                 [3, 4]]),
    b: ivy.array([[9, 10],
                  [11, 12]])
}, {
    a: ivy.array([[5, 6],
                  [7, 8]]),
    b: ivy.array([[13, 14],
                  [15, 16]])
}]
zero_pad(pad_width, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Input array to pad.

  • pad_width (Union[Iterable[Tuple[int]], Container]) – Number of values padded to the edges of each axis. Specified as ((before_1, after_1), … (before_N, after_N)), where N is number of axes of x.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • 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 – Padded array of rank equal to x with shape increased according to pad_width.

Examples

With ivy.Container input:

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

This should have hopefully given you an overview of the manipulation submodule, if you have any questions, please feel free to reach out on our discord!