copy_nest#

ivy.copy_nest(nest, /, include_derived=False, to_mutable=False)[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, default: False) – Whether to also recursive for classes derived from tuple, list and dict. Default is False.

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

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