atleast_3d#

ivy.atleast_3d(*arys, copy=None)[source]#

Convert inputs to arrays with at least three dimension. Scalar inputs are converted to 3-dimensional arrays, whilst higher-dimensional inputs are preserved.

Parameters:
  • arys (Union[Array, NativeArray, bool, Number]) – One or more array-like sequences. Non-array inputs are converted to arrays. Arrays that already have three or more dimensions are preserved.

  • copy (Optional[bool], 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. In case copy is False we avoid copying by returning a view of the input array.

Return type:

List[Array]

Returns:

ret – An array, or list of arrays, each with a.ndim >= 3. Copies are avoided where possible, and views with three or more dimensions are returned. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1).

Examples

>>> ary1 = ivy.array([5,6])
>>> ivy.atleast_3d(ary1)
ivy.array([[[5],
        [6]]])
>>> ary2 = ivy.array([[[3,4]]])
>>> ivy.atleast_3d(ary2)
ivy.array([[[3, 4]]])
>>> ary3 = ivy.array([[3,4],[9,10]])
>>> ivy.atleast_3d(6,7,ary3)
[ivy.array([[[6]]]), ivy.array([[[7]]]), ivy.array([[[ 3],
        [ 4]],
[[ 9],

[10]]])]

Array.atleast_3d(self, *arys, copy=None)[source]#

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

Parameters:
  • self (Array) – Input array. Cannot be a scalar input.

  • arys (Union[Array, bool, Number]) – An arbitrary number of input arrays.

  • copy (Optional[bool], 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. In case copy is False we avoid copying by returning

    a view of the input array.

Return type:

List[Array]

Returns:

ret – List of arrays, each with a.ndim >= 3. Copies are made only if necessary and views with three or more dimensions are returned. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1).

Examples

>>> a1 = ivy.array([[1,2,3]])
>>> a2 = ivy.array([4,8])
>>> a1.atleast_3d(a2,5,6)
[ivy.array([[[1],
        [2],
        [3]]]), ivy.array([[[4],
        [8]]]), ivy.array([[[5]]]), ivy.array([[[6]]])]
Container.atleast_3d(self, *arys, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Union[Container, Array, NativeArray]) – container with array inputs.

  • arys (Union[Container, Array, NativeArray, bool, Number]) – one or more container with array inputs.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The keychains 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:

ret – container or list of container where each elements within container is at least 3D. Copies are made only if necessary. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a view of shape (M, N, 1).

Examples

>>> ary1 = ivy.Container(a=ivy.array(1), b=ivy.array([3,4]),                            c=ivy.array([[5]]))
>>> ary2 = ivy.Container(a=ivy.array(9), b=ivy.array(2),                            c=ivy.array(3))
>>> ary1.atleast_3d(ary2)
[{
    a: ivy.array([[[1]]]),
    b: ivy.array([[[3],
                   [4]]]),
    c: ivy.array([[[5]]])
}, {
    a: ivy.array([[[9]]]),
    b: ivy.array([[[2]]]),
    c: ivy.array([[[3]]])
}]