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.

  • 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 at least 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)[source]#

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.

  • 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 >= 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)[source]#

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.

  • 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 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 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]])
}]