<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/tree/tree_api.py#L215-L249) |

Maps `func` through given structures up to `shallow_structure`.

    tf.keras.tree.map_structure_up_to(
        shallow_structure, func, *structures
    )

This is a variant of `map_structure` which only maps the given structures
up to `shallow_structure`. All further nested components are retained as-is.

#### Examples:

    shallow_structure = [None, None]
    structure = [[1, 1], [2, 2]]
    keras.tree.map_structure_up_to(shallow_structure, len, structure)
    [2, 2]

    shallow_structure = [None, [None, None]]
    keras.tree.map_structure_up_to(shallow_structure, str, structure)
    ['[1, 1]', ['2', '2']]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `shallow_structure` | A structure with layout common to all `structures`. |
| `func` | A callable that accepts as many arguments as there are structures. |
| `*structures` | Arbitrarily nested structures of the same layout. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A new structure with the same layout as `shallow_structure`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `structures` is empty or `func` is not callable. |
| `ValueError` | If one of the items in `structures` doesn't match the nested structure of `shallow_structure` according to the rules of `assert_same_structure`. Items in `structures` are allowed to be nested deeper than `shallow_structure`, but they cannot be shallower. |

<br />