copy_nest#

ivy.copy_nest(nest, /, include_derived=False, to_mutable=False, extra_nest_types=None)[source]#

Copy a nest deeply, but without copying leaves of the nest, only the nest lists, tuples and dicts are copied.

Parameters:
  • nest (Union[Array, NativeArray, Iterable]) – The nest to copy.

  • include_derived (bool) – Whether to also recursive for classes derived from tuple, list and dict. (default: False) Default is False.

  • to_mutable (bool) – Whether to convert the nest to a mutable form, changing all tuples to lists. (default: False) Default is False.

  • extra_nest_types (Optional[Union[type, Tuple[type]]]) – Types to recursively check when deciding whether to go deeper into the (default: None) nest or not

Return type:

Union[Array, NativeArray, Iterable]

Returns:

ret – The copied nest.

Examples

With ivy.Array input:

>>> nest = ivy.array([[1.,2.,3.],[7.,8.,9.]])
>>> copied_nest = ivy.copy_nest(nest)
>>> print(copied_nest)
ivy.array([[1., 2., 3.],
        [7., 8., 9.]])

With Iterable input:

>>> nest = [[1, 2, 3, 4, 5], [23, 24, 25, 26, 27]]
>>> copied_nest = ivy.copy_nest(nest, include_derived = True)
>>> print(copied_nest)
[[1, 2, 3, 4, 5], [23, 24, 25, 26, 27]]
>>> nest = ([23, 25, 1337], [63, 98, 6])
>>> copied_nest = ivy.copy_nest(nest, to_mutable = True)
>>> print(copied_nest)
[[23, 25, 1337], [63, 98, 6]]
>>> nest = {'first': [23., 24., 25], 'second': [46., 48., 50]}
>>> copied_nest = ivy.copy_nest(nest)
>>> print(copied_nest)
{'first': [23.0, 24.0, 25], 'second': [46.0, 48.0, 50]}