atleast_1d#

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

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

Parameters:

arys (Union[Array, NativeArray, bool, Number]) – One or more input arrays.

Return type:

List[Array]

Returns:

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

Examples

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

ivy.Array instance method variant of ivy.atleast_1d. This method simply wraps the function, and so the docstring for ivy.atleast_1d 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.

Return type:

List[Array]

Returns:

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

Examples

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

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

Parameters:
  • self (Union[Container, Array, NativeArray]) – the 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]]]) – 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 1d. 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_1d(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])
}]