Skip to main content

jax.tree_map, but for all datatypes and with input names

Project description

NamedTreemap

jax.tree_map, but for all datatypes and with input names

Getting Started

Installation

python3 -m pip install namedtreemap

Examples

import namedtreemap as ntm
from typing import Tuple, Any


def fn(prefix: Tuple[Any, ...], *items):
    print(prefix, items)
    return items[0] + 1


obj = {"3": {"2": [1, 2]}, "1": (0,)}
print("Original:", obj)  # Original: {'3': {'2': [1, 2]}, '1': (0,)}
obj = ntm.named_treemap(fn, obj, obj)
# ('3', '2', 0) (1, 1)   -   0 (int) is a list index
# ('3', '2', 1) (2, 2)   -   1 (int) is a list index
# ('1', 0.0) (0, 0)      -   0.0 (float) is a tuple index
print("Modified:", obj)  # Modified: {'3': {'2': [2, 3]}, '1': (1,)}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

namedtreemap-0.0.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

namedtreemap-0.0.1-py3-none-any.whl (2.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page