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.- 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)#
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.
- 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, copy=None, *arys, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#
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
]]]) – The keychains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.
- Return type:
List
[Container
]- Returns:
ret – container or list of container where each elements within container is atleast 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]]]) }]