nested_map

ivy.nested_map(x: Union[ivy.Array, ivy.NativeArray, Iterable], fn: Callable, include_derived: 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.

Parameters
  • 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.

  • 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.

Returns

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