ivy.nested_map(x: Union[ivy.Array, ivy.NativeArray, Iterable], fn: Callable, include_derived: bool = False, to_mutable: bool = False, max_depth: Optional[int] = None, depth: int = 0) → Union[ivy.Array, ivy.NativeArray, Iterable][source]

Applies a function on x in a nested manner, whereby all dicts, lists and tuples are traversed to their lowest leaves before applying the method and returning x. If x is not nested, the method is applied to x directly.

  • x (any) – The item to apply the mapped function to.

  • fn (callable) – The function to map onto x.

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

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

  • max_depth (int, optional) – The maximum nested depth to reach. Default is 1. Increase this if the nest is deeper.

  • depth (int, used internally) – Placeholder for tracking the recursive depth, do not yet this parameter.


x following the applicable of fn to it’s nested leaves, or x itself if x is not nested.

Supported Frameworks:

empty jax_logo empty tf_logo empty pytorch_logo empty mxnet_logo empty numpy_logo empty