to_list#
- ivy.to_list(x, /)[source]#
Create a (possibly nested) list from input array.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array.- Return type:
List
- Returns:
ret – A list representation of the input array
x
.
Examples
With
ivy.Array
input:>>> x = ivy.array([-1, 0, 1]) >>> y = ivy.to_list(x) >>> print(y) [-1, 0, 1]
>>> x = ivy.array([[ 1.1, 2.2, 3.3], ... [-4.4, -5.5, -6.6]]) >>> y = ivy.to_list(x) >>> print(y) [[1.100000023841858,2.200000047683716,3.299999952316284], [-4.400000095367432,-5.5,-6.599999904632568]]
>>> x = ivy.array([[[-1, 0, 1], ... [ 1, 0, -1]], ... [[ 1, -1, 0], ... [ 1, 0, -1]]]) >>> y = ivy.to_list(x) >>> print(y) [[[-1, 0, 1], [1, 0, -1]], [[1, -1, 0], [1, 0, -1]]]
With a mix of
ivy.Container
andivy.Array
input:>>> x = ivy.Container(a=ivy.array([-1, 0, 1])) >>> y = ivy.to_list(x) >>> print(y) { a: [-1, 0, 1] }
>>> x = ivy.Container(a=ivy.array([[-1, 0, 1], ... [-1, 0, 1], ... [1, 0, -1]])) >>> y = ivy.to_list(x) >>> print(y) { a: [[-1, 0, 1], [-1, 0, 1], [1,0,-1]] }
>>> x = ivy.Container(a=ivy.array([[[-1, 0, 1],[1, 0, -1]], ... [[1, -1, 0],[1, 0, -1]]])) >>> y = ivy.to_list(x) >>> print(y) { a: [[[-1, 0, 1], [1, 0, -1]], [[1, -1, 0], [1, 0, -1]]] }
- Array.to_list(self, /)[source]#
ivy.Array instance method variant of ivy.to_list. This method simply wraps the function, and so the docstring for ivy.to_list also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.- Return type:
List
- Returns:
ret – A list representation of the input array
x
.
Examples
With
ivy.Array
instance method:>>> x = ivy.array([0, 1, 2]) >>> y = x.to_list() >>> print(y) [0, 1, 2]
- Container.to_list(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.to_list. This method simply wraps the function, and so the docstring for ivy.to_list also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret – A container with list representation of the leave arrays.
Examples
With one
ivy.Container
instances:>>> x = ivy.Container(a=ivy.array([0, 1, 2])) >>> y = x.to_list() >>> print(y) {a:[0,1,2]}