atleast_2d#

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

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

Parameters:

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

Return type:

List[Array]

Returns:

ret – An array, or list of arrays, each with atleast 2D. Copies are made only if necessary.

Examples

>>> ary1 = ivy.array(5)
>>> ivy.atleast_2d(ary1)
ivy.array([[5]])
>>> ary2 = ivy.array([[[3,4]]])
>>> ivy.atleast_2d(ary2)
ivy.array([[[3, 4]]])
>>> ivy.atleast_2d(6,7,8)
[ivy.array([[6]]), ivy.array([[7]]), ivy.array([[8]])]
Array.atleast_2d(self, *arys, copy=None)#

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

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

  • arys (Array) – An arbitrary number of input arrays.

Return type:

List[Array]

Returns:

ret – List of arrays, each with a.ndim >= 2. Copies are made only if necessary.

Examples

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

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

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

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

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

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

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

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

Return type:

List[Container]

Returns:

ret – container or list of container where each elements within container is atleast 2D. Copies are made only if necessary.

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_2d(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]])
}]